在本地 kubernetes 集群中安装 kubesphere
2021-01-13 tech kubernetes kubespere 14 mins 12 图 5093 字
kubesphere 是青云开源的 kubernetes 管理平台,可以纳管原生 的 Kubernetes。我个人挺喜欢他们的UI设计,从kubesphere 1.0 就关注了,当时无法在本地环境中安装,只能蹭了一波他们销售发放的优惠券在云上安装体验。近期又尝试在我本地纯净的kubernetes集群上安装 kubesphere 3.0,虽然仍然有一小番波折,不过总算是安装好了。这篇文章记录相关的要点。
我的 kubernetes 版本 v1.20.2,没有任何可用的外部存储,所能依靠的只有 local-storage。
一、kubesphere前置条件
-
节点可用资源:1c2g
-
安装默认storage class
创建 sc。
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: local-storage provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer
参考:存储类
配置为默认 sc
kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
查看已经运行ok
kubectl get sc
二、安装pv
跌跌撞撞一共起了6个 pv,如图:
分别用于redis、Prometheus、openldap,如果后期安装 service mesh(可选),还需要为 es 起 对应的pv。
以下的yaml文件注意修改亲和性相关的配置。
-
创建目录
mkdir -p /app/redis /app/prometheus1 /app/prometheus2 /app/openldap /app/es/data /app/es/data2
-
redis,10G
apiVersion: v1 kind: PersistentVolume metadata: name: redis-pv spec: capacity: storage: 10Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /app/redis nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 10.184.0.131
-
Prometheus,20G
apiVersion: v1 kind: PersistentVolume metadata: name: prometheus-pv-1 spec: capacity: storage: 20Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /app/prometheus1 nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 10.184.0.131 --- apiVersion: v1 kind: PersistentVolume metadata: name: prometheus-pv-2 spec: capacity: storage: 20Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /app/prometheus2 nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 10.184.0.131
-
openldap,10G
apiVersion: v1 kind: PersistentVolume metadata: name: prom2-pv spec: capacity: storage: 10Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /app/openldap nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 10.184.0.133
-
service mesh/es,20G (可选)
apiVersion: v1 kind: PersistentVolume metadata: name: es-data-pv spec: capacity: storage: 20Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /app/es/data nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 10.184.0.131 --- apiVersion: v1 kind: PersistentVolume metadata: name: es-data2-pv spec: capacity: storage: 20Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /app/es/data2 nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 10.184.0.131 - 10.184.0.132 - 10.184.0.133
三、安装 kubesphere
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/kubesphere-installer.yaml
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/cluster-configuration.yaml
等待20分钟左右。
kubectl get po --all-namespaces
可以通过命令行查看安装过程。初始只有一个Pod ks-installer,它在Pod中运行ansible,可以查看它的日志,如果有错误就针对性地解决错误:
kubectl logs -f -n kubesphere-system ks-installer-xxx
安装完成后日志应该如下:
四、界面尝鲜
五、开启service mesh
至此已经可以使用了。我尝试了开启 service mesh,有三个pod一直无法启动。因为只是随手玩玩,就不深究了。kubesphere的service mesh还是老版本的istio,就是还处于分离状态的组件,不是1.5版本之后的单体istio。
开启办法参考文档:https://kubesphere.io/docs/pluggable-components/service-mesh/
页面左上角 平台管理->集群管理->自定义资源crd-> 搜索 clusterconfiguration -> 进入
拉到最后,将 service mesh 配置 enabled 改为 true,即可。
查看安装进度:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
六、遇到的错误
-
无法登录,account not active
查阅了不少 github issue,基本的情况是openldap那个容器相关的存储或者网络有问题。我一开始没有挂pv,估计是这个原因导致的问题。
实际上挂上pv之后仍然不行。最后重启kubesphere 所有的pod之后可以登陆了。
-
service mesh 仍然有3个pod无法启动。
因为只是顺手在做,并不使用,先记录一下,目前没去理。
七、卸载kubesphere
参考使用kubesphere的卸载脚本即可:
https://github.com/kubesphere/ks-installer/blob/release-3.1/scripts/kubesphere-delete.sh