在Kubernetes集群部署kubesphere

2024-09-26 420 0

kubesphere 安装要求有默认storageclass

NFS部署

yum install -y nfs-utils # CentOS
apt install -y nfs-kernel-server # Ubuntu

mkdir -p /data/nfs
echo "/data/nfs *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports

systemctl restart nfs-server
systemctl enable nfs-server
mkdir -p /data/nfs/kubesphere
[root@nfs ~]# exportfs -rv
exporting *:/data/nfs

K8S Master/Client 节点NFS客户端

yum install -y nfs-utils # CentOS
apt-get install -y nfs-common # Ubuntu

部署动态StoragesClass

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

nfs.path 目录需要提前创建

helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/

helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
    --set nfs.server=192.168.77.11 \
    --set nfs.path=/data/nfs/kubesphere \
    -n nfs-provisioner \
    --create-namespace

# --set image.repository=registry.sundayhk.com/k8s/sig-storage/nfs-subdir-external-provisioner \

设置为默认storageclass (重点)

kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
root@ks-master01:~# kubectl get storageclass -n nfs-provisioner
NAME         PROVISIONER                                     RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-client   cluster.local/nfs-subdir-external-provisioner   Delete          Immediate           true                   95s

root@ks-master01:~# kubectl get pod -n nfs-provisioner
NAME                                               READY   STATUS    RESTARTS   AGE
nfs-subdir-external-provisioner-768dc5f875-77z58   1/1     Running   0          77s

测试

# kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/nfs-subdir-external-provisioner/master/deploy/test-claim.yaml 

# test-claim.yaml
cat <<EOF | kubectl apply -f -
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-claim
spec:
  storageClassName: nfs-client
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Mi
EOF
# kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/nfs-subdir-external-provisioner/master/deploy/test-pod.yaml

# test-pod
cat <<EOF | kubectl apply -f -
kind: Pod
apiVersion: v1
metadata:
  name: test-pod
spec:
  containers:
  - name: test-pod
    image: busybox:1.28
    command:
      - "/bin/sh"
    args:
      - "-c"
      - "touch /mnt/SUCCESS && exit 0 || exit 1"
    volumeMounts:
      - name: nfs-pvc
        mountPath: "/mnt"
  restartPolicy: "Never"
  volumes:
    - name: nfs-pvc
      persistentVolumeClaim:
        claimName: test-claim
EOF
root@ks-master01:~# kubectl get pod test-pod
NAME       READY   STATUS      RESTARTS   AGE
test-pod   0/1     Completed   0          73s
root@ks-master01:~# kubectl get pvc
NAME         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
test-claim   Bound    pvc-3707b82e-cf26-479f-8d0c-84ad7e6bce19   1Mi        RWX            nfs-client     87s

NFS服务器查看

[root@nfs nfs]# ls -l /data/nfs/kubesphere/default-test-claim-pvc-3707b82e-cf26-479f-8d0c-84ad7e6bce19/SUCCESS
-rw-r--r--. 1 root root 0 Sep 26 01:17 /data/nfs/kubesphere/default-test-claim-pvc-3707b82e-cf26-479f-8d0c-84ad7e6bce19/SUCCESS

删除测试POD PVC

kubectl delete pod test-pod
kubectl delete pvc test-claim

Kubesphere部署

确保现有的 Kubernetes 集群满足所有要求之后,您可以使用 kubectl 以默认最小安装包来安装 KubeSphere。

  1. 执行以下命令以开始安装:
wget https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/kubesphere-installer.yaml
wget https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/cluster-configuration.yaml

# 修改ks-installer:v3.4.1为ks-installer:v3.4.1-patch.0
# 该补丁镜像更新证书有效期到2051年,解决了devops s2i证书2024-02-14过期问题
sed -i 's#ks-installer:v3.4.1#ks-installer:v3.4.1-patch.0#' kubesphere-installer.yaml
kubectl apply -f kubesphere-installer.yaml
kubectl apply -f cluster-configuration.yaml

https://ask.kubesphere.io/forum/d/23227-s2ifu-wu-bu-ke-yong-ti-shi-zheng-shu-shi-xiao/8

  1. 检查安装日志:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

TASK [ks-core/prepare : KubeSphere | Generating kubeconfig-admin] **************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=30   changed=22   unreachable=0    failed=0    skipped=17   rescued=0    ignored=0   
Start installing monitoring
Start installing multicluster
Start installing openpitrix
Start installing network
**************************************************
Waiting for all tasks to be completed ...
task network status is successful  (1/4)
task openpitrix status is successful  (2/4)
task multicluster status is successful  (3/4)

task monitoring status is successful  (4/4)
**************************************************
Collecting installation results ...
  1. 使用 kubectl get pod --all-namespaces 查看所有 Pod 在 KubeSphere 相关的命名空间是否正常运行。如果是正常运行,请通过以下命令来检查控制台的端口(默认为 30880):
kubectl get svc/ks-console -n kubesphere-system

root@ks-master01:~# kubectl get svc/ks-console -n kubesphere-system
NAME         TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
ks-console   NodePort   10.233.15.88   <none>        80:30880/TCP   10m
  1. 确保在安全组中打开了 30880 端口,通过 NodePort (IP:30880) 使用默认帐户和密码 (admin/P@88w0rd) 访问 Web 控制台。

image.png

https://kubesphere.io/zh/docs/v3.4/installing-on-kubernetes/introduction/overview/

相关文章

KubeSphere DevOps 流水线JAVA项目配置
虚拟机热添加内存 Kubernetes未生效
Containerd镜像加速及私有仓库配置(用户密码和忽略HTTPS)
使用KubeKey快速部署Kubernetes集群1.28.8
Rancher 快速创建RKE K8S集群
Kubernetes日志收集方案 EFK Pod部署

发布评论