K8S安裝Kubesphere


准備工作

安裝Helm

curl -L https://git.io/get_helm.sh | bash

創建賬戶

cat > heml-rbac.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system
EOF

構建

kubectl apply -f heml-rbac.yaml

初始化tiller

helm init --service-account=tiller --tiller-image=sapcc/tiller:v2.16.3 --history-max 300

檢查tiller初始化情況

kube-system     tiller-deploy-5fdc6844fb-mfxc4             1/1     Running   0          10m

安裝 OpenEBS 創建 LocalPV 存儲類型

k8s-node1: mater節點名稱。

前提條件

  • 已有 Kubernetes 集群,並安裝了 kubectl 或 Helm
  • Pod 可以被調度到集群的 master 節點(可臨時取消 master 節點的 Taint)

關於第二個前提條件,是由於安裝 OpenEBS 時它有一個初始化的 Pod 需要在 master 節點啟動並創建 PV 給 KubeSphere 的有狀態應用掛載。因此,若您的 master 節點存在 Taint,建議在安裝 OpenEBS 之前手動取消 Taint,待 OpenEBS 與 KubeSphere 安裝完成后,再對 master 打上 Taint,以下步驟供參考:

  1. 例如本示例有一個 master 節點,節點名稱即 master,可通過以下命令查看節點名稱:
kubectl get node -o wide
NAME        STATUS   ROLES    AGE    VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
k8s-node1   Ready    master   168m   v1.17.5   10.0.2.15     <none>        CentOS Linux 7 (Core)   4.4.228-2.el7.elrepo.x86_64   docker://19.3.8
k8s-node2   Ready    <none>   154m   v1.17.5   10.0.2.8      <none>        CentOS Linux 7 (Core)   4.4.228-2.el7.elrepo.x86_64   docker://19.3.8
k8s-node3   Ready    <none>   154m   v1.17.5   10.0.2.9      <none>        CentOS Linux 7 (Core)   4.4.228-2.el7.elrepo.x86_64   docker://19.3.8
  1. 確認 master 節點是否有 Taint,如下看到 master 節點有 Taint。
kubectl describe node k8s-node1 | grep Taint
Taints:             node-role.kubernetes.io/master:NoSchedule
  1. 去掉 master 節點的 Taint
kubectl taint nodes k8s-node1 node-role.kubernetes.io/master:NoSchedule-

此時可參考安裝 OpenEBS 的步驟繼續操作。

安裝 OpenEBS

  1. 創建 OpenEBS 的 namespace,OpenEBS 相關資源將創建在這個 namespace 下:
kubectl create ns openebs
  1. 安裝 OpenEBS,以下列出兩種方法,可參考其中任意一種進行創建:

A. 若集群已安裝了 Helm,可通過 Helm 命令來安裝 OpenEBS:

helm install --namespace openebs --name openebs stable/openebs --version 1.5.0

B. 除此之外還可以通過 kubectl 命令安裝:

$ kubectl apply -f https://openebs.github.io/charts/openebs-operator-1.5.0.yaml
  1. 安裝 OpenEBS 后將自動創建 4 個 StorageClass,查看創建的 StorageClass:
kubectl get sc
NAME                        PROVISIONER                                                AGE
openebs-device              openebs.io/local                                           10h
openebs-hostpath            openebs.io/local                                           10h
openebs-jiva-default        openebs.io/provisioner-iscsi                               10h
openebs-snapshot-promoter   volumesnapshot.external-storage.k8s.io/snapshot-promoter   10h
  1. 如下將 openebs-hostpath設置為 默認的 StorageClass:
kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
storageclass.storage.k8s.io/openebs-hostpath patched
  1. 至此,OpenEBS 的 LocalPV 已作為默認的存儲類型創建成功。可以通過命令 kubectl get pod -n openebs來查看 OpenEBS 相關 Pod 的狀態,若 Pod 的狀態都是 running,則說明存儲安裝成功。

在 Kubernetes 安裝 KubeSphere

安裝 KubeSphere

根據集群資源情況,使用 kubectl 安裝 KubeSphere

最小化安裝 KubeSphere

若集群可用 CPU > 1 Core 且可用內存 > 2 G,可以使用以下命令最小化安裝 KubeSphere:

kubectl apply -f https://raw.githubusercontent.com/kubesphere/ks-installer/master/kubesphere-minimal.yaml

完整安裝 KubeSphere

若集群可用 CPU > 8 Core 且可用內存 > 16 G,可以使用以下命令完整安裝 KubeSphere。

注意,應確保集群中有一個節點的可用內存大於 8 G。

kubectl apply -f https://raw.githubusercontent.com/kubesphere/ks-installer/master/kubesphere-complete-setup.yaml

提示:若您的服務器提示無法訪問 GitHub,可將 kubesphere-minimal.yamlkubesphere-complete-setup.yaml 文件保存到本地作為本地的靜態文件,再參考上述命令進行安裝。

查看是否安裝狀態

kubectl get pods --all-namespaces
kubesphere-system   ks-installer-75b8d89dff-9v4xf       0/1     Running   0          94s

驗證與訪問

  1. 查看滾動刷新的安裝日志,請耐心等待安裝成功。
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

說明:安裝過程中若遇到問題,也可以通過以上日志命令來排查問題。

  1. 通過 kubectl get pod --all-namespaces查看 KubeSphere 相關 namespace 下所有 Pod 狀態是否為 Running。確認 Pod 都正常運行后,可使用 IP:30880訪問 KubeSphere UI 界面,默認的集群管理員賬號為 admin/P@88w0rd

參考文檔: https://kubesphere.io/docs/zh-CN/installation/install-on-k8s/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM