K8s集群中部署KubeSphere

​ 在k8s集群中部署kubesphere需要先创建一个名为managed-nfs-storage 的storageclass,这里我用了最简单的nfs方式,当然也可以用ceph或者其他方式实现.

1. 共享存储准备

1.1 创建nfs

yum install nfs-utils -y
systemctl enable --now nfs-utils

配置

# cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/data/k8s *(rw,sync,no_root_squash)
## 用作kubesphere
/data/k8s/kubesphere *(rw,sync,no_root_squash)
/data/ehelp *(rw,sync,no_root_squash)
/data/k8s/wework/images *(rw,sync,no_root_squash)

重启服务

systemctl restart nfs-utils.service

验证nfs

# showmount -e 192.168.31.109
Export list for 192.168.31.109:
/data/k8s/wework/images *
/data/ehelp             *
/data/k8s               *

2. 创建storageclass

2.1 获取yaml模板

for file in class.yaml deployment.yaml rbac.yaml ; do wget https://raw.githubusercontent.com/kubernetes-incubator/external-storage/master/nfs-client/deploy/$file ; done

修改nfs的ip和路径

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: registry.cn-beijing.aliyuncs.com/pylixm/nfs-subdir-external-provisioner:v4.0.0
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 192.168.31.109
            - name: NFS_PATH
              value: /data/k8s/kubesphere
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.31.109
            path: /data/k8s/kubesphere

2.2 设置默认StorageClass

执行前

root@master-01:~/kk# kubectl get sc
NAME                  PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
managed-nfs-storage   fuseim.pri/ifs   Delete          Immediate           false                  14h

将managed-nfs-storage设置成默认存储类

kubectl patch storageclass managed-nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

执行后

root@master-01:~/kk# kubectl get sc
NAME                            PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
managed-nfs-storage (default)   fuseim.pri/ifs   Delete          Immediate           false                  14h

3. 创建KubeSphere资源

可以直接下载

kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.2.1/kubesphere-installer.yaml
   
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.2.1/cluster-configuration.yaml

或者下载下来后部署

kubectl apply -f kubesphere-installer.yaml

kubectl apply -f cluster-configuration.yaml

查看安装进度

kubectl logs -n kubesphere-system $(kubectl get pods -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

请添加图片描述

此时浏览器直接访问任意node节点的30880端口即可

默认用户名admin,密码P@88w0rd

请添加图片描述

4. 添加应用商店

搜索ClusterConfiguration支持模糊搜索写clusterconfig或则cluster都可以只要找对就行

请添加图片描述

点击编辑yaml

请添加图片描述

将store的enable: false改为true

请添加图片描述

这样就能打开应用商店了

请添加图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐