Administrator
Published on 2023-02-09 / 36 Visits
0
0

kubernetes 中部署kubesphere

本文是在原本搭建好的K8S集群中部署kubesphere,所选版本为3.1.1

如果需要搭建k8s集群可参考如下链接,注意部署有版本依赖,本次部署的K8S版本为1.18.2,kubesphere版本为3.1.1 https://www.garafana.com/archives/k8s%E6%90%AD%E5%BB%BA01-k8s%E9%9B%86%E7%BE%A4

前提配置需要,安装NFS做存储卷

#此步骤为检查机器是否有安装果NFS
rpm -qa |egrep "nfs-utils|rpcbind"

#找一台机器部署NFS,直接yum安装
yum -y install nfs-utils rpcbind

#创建NFS共享目录,可随意指配
mkdir -p /data/nfs

#添加NFS规则目录配置,注意修改目录与机器ip地址
vim /etc/exports
/data/nfs 172.19.58.0/16(rw,no_root_squash,no_all_squash,sync)

#刷新配置
exportfs -r

#配置开启自启与启动
systemctl start nfs
systemctl start rpcbind
systemctl enable nfs
systemctl ebable rpcbind

NFS客户端安装

#检查是否安装过NFS客户端,如果有则跳过安装
rpm -qa|grep nfs-utils

#安装NFS客户端
yum -y install nfs-utils

#创建NFS挂在位置,可随意指配位置
mkdir /data/nfs -p

#挂在NFS,注意修改ip与目录
mount -t nfs 172.19.58.188:/data/nfs /data/nfs -o proto=tcp -o nolock

#配置开启自动挂载
echo '172.19.58.188:/data/nfs                   /data/nfs               nfs     defaults        0 0' >>/etc/fstab

授权NFS存储类权限

#直接上yaml文件,kubesphere要求default下面有默认存储类所以不需要修改

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
    # replace with namespace where provisioner is deployed
  namespace: default
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

#在master节点或者能使用kubectl的机器运行
kubectl apply -f 你的文件目录以及文件名

#创建存储类
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage   #名字根据自己喜好修改
provisioner: nfs-storage 
parameters:
  archiveOnDelete: "false"

kubectl apply -f 你的文件目录以及文件名

#更改存储类为默认存储类型,如果上方创建存储类名称修改,则下方命令也需要修改
kubectl patch storageclass managed-nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

#创建pv
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfspv1 #名称自行修改
spec:
  
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: managed-nfs-storage
  nfs:
    path: /data/nfs
    server: 192.168.62.100

步骤kubesphere

#安装kubesphere
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
   
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml

#在master节点反复运行如下命令检查是否为runnling
kubectl get pod -A |grep installer

#状态为runnling则检查日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f


#日志检查到出现如下信息则安装成功。直接访问提供的地址以及账号密码
#####################################################
###              Welcome to KubeSphere!           ###
#####################################################

Console: http://192.168.62.100:30880
Account: admin
Password: P@88w0rd

为kubesphere 安装devops流水线

#流水线需要两个pv,所以提前创建好,直接复制如下yaml文件
#创建PV
apiVersion: v1
kind: PersistentVolume
metadata:
  name: minio #名称可修改
spec:
  
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: managed-nfs-storage
  nfs:
    path: /data/nfs
    server: 192.168.62.100
---   
apiVersion: v1
kind: PersistentVolume
metadata:
  name: openldap #名称可修改
spec:
  
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: managed-nfs-storage
  nfs:
    path: /data/nfs
    server: 192.168.62.100
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins
spec:
  
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: managed-nfs-storage
  nfs:
    path: /data/nfs
    server: 192.168.62.100

kubectl apply -f 你的文件名称

#下载devops的yaml文件并修改文件配置信息
wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml

#在文件中找到如下字段修改
devops:
  enabled: true # 将“false”更改为“true”。

#执行运行文件#注意使用什么版本要记得修改

kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
   
kubectl apply -f cluster-configuration.yaml

#检查安装日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

#反复检查pod状态,可跳过
kubectl get pod -A |egrep "minio|openldap"

#安装devops流水线文档地址
https://v3-1.docs.kubesphere.io/zh/docs/pluggable-components/devops/

Comment