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/

猜你喜欢

转载自www.cnblogs.com/chinda/p/13197246.html