在K8s上安装KubeSphere
在K8s上安装KubeSphere
准备
- 确认现有的
Kubernetes
版本为1.20.x, 1.21.x, 1.22.x, 1.23.x (experimental)
,可以执行kubectl version
来确认 - 集群现有的可用内存至少在
2G
以上。 如果是执行的allinone
安装,那么执行free -g
可以看下可用资源 - KubeSphere 需配合持久化存储使用,执行
kubectl get sc
查看当前环境中的存储类型 (当使用默认存储类型时,配置文件中可以不填存储相关信息)。 - CSR signing 功能在 kube-apiserver 中被激活,参考 RKE installation issue。
free -g && \
kubectl version && \
kubectl get sc && kubectl get pv
# 如果有结果说明有storageclass和persistentvolume
kubectl get pod -A |grep kube-controller-manager|awk '{print $2}'|xargs -I % kubectl get pod % -n kube-system -o yaml |grep 'cluster-signing'
# 正确输出结果
#--cluster-signing-cert-file=/etc/kubernetes/pki/ca.crt
#--cluster-signing-duration=87600h
#--cluster-signing-key-file=/etc/kubernetes/pki/ca.key
添加默认的StorageClass
# storage-class.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: kube-sphere-storage-class
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/no-provisioner
# no-provisioner 是因为 Local Persistent Volume 目前尚不支持 Dynamic Provisioning动态生成PV,所以我们需要提前手动创建PV
volumeBindingMode: WaitForFirstConsumer
# 设置默认 storageclass
# kubectl patch sc kube-sphere-storage-class -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
kubectl apply -f storage-class.yaml
kubectl patch sc kube-sphere-storage-class -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
添加Local-PV
# local-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: kube-sphere-local-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
# https://kubernetes.io/zh-cn/docs/concepts/storage/persistent-volumes/#access-modes
persistentVolumeReclaimPolicy: Delete
storageClassName: kube-sphere-storage-class
local:
path: /data/k8s/pv/kubesphere
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- k8s.node2
kubectl apply -f local-pv.yaml
下载yaml
下载地址 需要下载里面的 kubesphere-installer.yaml
curl -L https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/kubesphere-installer.yaml -o kubesphere-installer.yaml && \
curl -L https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/cluster-configuration.yaml -o kubesphere-cluster-configuration.yaml
安装
kubectl apply -f kubesphere-installer.yaml
kubectl apply -f kubesphere-cluster-configuration.yaml
查看进度和日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-installer -o jsonpath='{.items[0].metadata.name}') -f
问题
没有找到StorageClass
TASK [preinstall : KubeSphere | Stopping if default StorageClass was not found] ***
fatal: [localhost]: FAILED! => {
"assertion": "\"(default)\" in default_storage_class_check.stdout",
"changed": false,
"evaluated_to": false,
"msg": "Default StorageClass was not found !"
}
没有正确输出启动日志
## 没有正确输出启动日志,启动日志停在以下位置时
2024-11-03T16:09:37+08:00 INFO : QUEUE add all HookRun@OnStartup
2024-11-03T16:09:37+08:00 INFO : Running schedule manager ...
2024-11-03T16:09:37+08:00 INFO : MSTOR Create new metric shell_operator_live_ticks
2024-11-03T16:09:37+08:00 INFO : MSTOR Create new metric shell_operator_tasks_queue_length
2024-11-03T16:09:37+08:00 INFO : GVR for kind 'ClusterConfiguration' is installer.kubesphere.io/v1alpha1, Resource=clusterconfigurations
## 需要执行以下命令 kubectl apply -f kubesphere-cluster-configuration.yaml
下载镜像失败
-
# 问题描述: ImagePullBackOff kubesphere-system ks-installer-846c78ddbf-wtrxj 0/1 ImagePullBackOff 0 20m # 解决: 在 /etc/docker/daemon.json 中添加镜像配置 "registry-mirrors": ["https://docker.rainbond.cc"]
监控和Minio的Pod调度异常
可以从节点亲和性,存储空间要求等方面进行排查
我这里的问题是pv的存储空间不够,无法满足PVC的要求,所以无法调度成功
# 查看现有的pvc存储要求
kubectl get pvc -n kubesphere-monitoring-system -o yaml |grep 'storage: 20Gi'
# 把PVC配置存储到文件
kubectl get pvc -n kubesphere-monitoring-system -o yaml > pvc-back.yaml
#删除之前无法调度的PVC
kubectl get pvc -A
kubectl delete pvc -n namespace pvc-name
# 修改pvc-back.yaml里面的storage相关配置, 重新创建pvc
kubectl apply -f pvc-back.yaml
LOCAL-PV目录要手动创建
Local pv的目录需要自己在对应的节点上创建,不然容器无法正常启动
验证安装
#####################################################
### Welcome to KubeSphere! ###
#####################################################
Console: http://192.168.0.2:30880
Account: admin
Password: P@88w0rd
NOTES:
1. After you log into the console, please check the
monitoring status of service components in
the "Cluster Management". If any service is not
ready, please wait patiently until all components
are up and running.
2. Please change the default password after login.
#####################################################
https://kubesphere.io 20xx-xx-xx xx:xx:xx
#####################################################