1. 程式人生 > 其它 >Kubernetes 叢集線上部署mini KubeSphere

Kubernetes 叢集線上部署mini KubeSphere

KubeSphere 願景是打造一個以 Kubernetes 為核心的雲原生分散式作業系統,它的架構可以非常方便地使第三方應用與雲原生生態元件進行即插即用(plug-and-play)的整合,支援雲原生應用在多雲與多叢集的統一分發和運維管理。

除了在 Linux 機器上安裝 KubeSphere 之外,您還可以將其直接部署在現有的 Kubernetes 叢集上。

一、安裝前提

  • 如需在 Kubernetes 上安裝 KubeSphere v3.1.1,您的 Kubernetes 版本必須為:1.17.x、1.18.x、1.19.x 或 1.20.x。
  • 確保您的機器滿足最低硬體要求:CPU > 1 核,記憶體 > 2 GB。
  • 在安裝之前,需要配置 Kubernetes 叢集中的預設儲存型別。

二、配置預設storageclass

配置預設storageclass,以下以nfs為預設storageclass為例:

一. 搭建storageclass
1、node節點安裝nfs服務

yum -y install nfs-utils rpcbind

  

2、啟動nfs並設為開機自啟:

systemctl start nfs && systemctl enable nfs
systemctl start rpcbind && systemctl enable rpcbind

  

3、node節點建立共享掛載目錄

mkdir -pv /data/nfs

  

4、編輯/etc/exports檔案(網段根據自己的情況寫)

[root@master2 ~]# cat /etc/exports
/data/nfs  *(rw,no_root_squash,no_all_squash)

5、檢視

[root@master2 ~]# showmount -e
Export list for k8s-node1:
/data/nfs *

  

6、修改deployment.yaml檔案

cat deployment.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-provisioner
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
   name: nfs-provisioner-runner
   namespace: default
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: ["watch", "create", "update", "patch"]
   -  apiGroups: [""]
      resources: ["services", "endpoints"]
      verbs: ["get","create","list", "watch","update"]
   -  apiGroups: ["extensions"]
      resources: ["podsecuritypolicies"]
      resourceNames: ["nfs-provisioner"]
      verbs: ["use"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-provisioner
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-client-provisioner
spec:
  selector:
    matchLabels:
      app: nfs-client-provisioner
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccount: nfs-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: nfs-client
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 10.11.99.141
            - name: NFS_PATH
              value: /data/nfs
      volumes:
        - name: nfs-client
          nfs:
            server: 10.11.99.141
            path: /data/nfs
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-storage
provisioner: fuseim.pri/ifs
reclaimPolicy: Retain

  

7、部署yaml檔案

kubectl apply -f  deployment.yaml

  

8、檢視服務

kubectl get pods
NAME                                      READY   STATUS    RESTARTS   AGE
nfs-client-provisioner-6d4469b5b5-bh6t9   1/1     Running   0          73m

  

9、列出你的叢集中的StorageClass

kubectl get storageclass
NAME                      PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
managed-nfs-storage        fuseim.pri/ifs   Delete          Immediate           false                  77m

  

10、標記一個StorageClass為預設的 (是storageclass的名字也就是你部署的StorageClass名字是啥就寫啥)

kubectl patch storageclass nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

  

11、驗證你選用為預設的StorageClass

kubectl get storageclass
NAME                            PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-storage (default)   fuseim.pri/ifs   Delete          Immediate           false                  77m

  

三、部署 KubeSphere

確保您的機器滿足安裝的前提條件之後,可以按照以下步驟安裝 KubeSphere。

  1. 執行以下命令開始安裝:

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

 

2、安裝 

經過一段時間的安裝後,看到以下介面則表示安裝成功:

3、登入驗證

登入console:http://10.11.99.141:30880/

賬號:admin

密碼:P@88w0rd

平臺管理:

叢集管理