【kubernetes】在k8s集群环境上,部署kubesphere

部署kubesphere

学习于尚硅谷kubesphere课程

前置环境配置-部署默认存储类型

这里使用nfs

bash 复制代码
#所有节点安装
yum install -y nfs-utils
bash 复制代码
# 在master节点执行以下命令 
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
# 执行以下命令,启动 nfs 服务;创建共享目录
mkdir -p /nfs/data
# 在master执行
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
# 使配置生效
exportfs -r
#检查配置是否生效
exportfs
bash 复制代码
#在从节点执行(选做)
showmount -e 192.168.8.11
mkdir -p /nfs/data
mount -t nfs 192.168.8.11:/nfs/data /nfs/data

配置存储,注意修改nfs服务的IP

bash 复制代码
#创建sc.yaml,
kubectl apply -f sc.yaml

##确认配置是否生效
kubectl get sc

sc.yaml

yaml 复制代码
## 创建了一个存储类
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-storage
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
  archiveOnDelete: "true"  ## 删除pv的时候,pv的内容是否要备份

---
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-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2
          # resources:
          #    limits:
          #      cpu: 10m
          #    requests:
          #      cpu: 10m
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: k8s-sigs.io/nfs-subdir-external-provisioner
            - name: NFS_SERVER
              value: 192.168.8.11 ## 指定自己nfs服务器地址
            - name: NFS_PATH  
              value: /nfs/data  ## nfs服务器共享的目录
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.8.11
            path: /nfs/data
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

部署kubesphere

bash 复制代码
#下载安装配置文件
wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml
wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml
bash 复制代码
#无需修改,直接apply
kubectl apply -f kubesphere-installer.yaml

#需要修改一些配置 启用所需插件,修改网络策略等
kubectl apply -f cluster-configuration.yaml

#查看kubesphere安装状态
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

#等待安装完成即可,过程有点漫长
bash 复制代码
#查看一下,是否有pod非running状态
kubectl get pod -A
bash 复制代码
#查看一下pod,未running的原因
kubectl describe pod  -n kubesphere-monitoring-system prometheus-k8s-0
kubectl describe pod  -n kubesphere-monitoring-system prometheus-k8s-1
kubectl describe pod  -n kubesphere-system openpitrix-import-job-8qczq
bash 复制代码
#解决上面的问题
kubectl -n kubesphere-monitoring-system create secret generic kube-etcd-client-certs  --from-file=etcd-client-ca.crt=/etc/kubernetes/pki/etcd/ca.crt  --from-file=etcd-client.crt=/etc/kubernetes/pki/apiserver-etcd-client.crt  --from-file=etcd-client.key=/etc/kubernetes/pki/apiserver-etcd-client.key

等会再看看pod状态。

测试访问kubesphere

相关推荐
默 唁4 小时前
win11系统 Docker Desktop提示Docker Engine stopped解决全过程记录
docker·容器
Godlovesea6 小时前
ubuntu安装docker 无法拉取问题
云原生·eureka
计算机毕设定制辅导-无忧学长6 小时前
Docker 与持续集成 / 持续部署(CI/CD)的集成(一)
ci/cd·docker·容器
Yuanymoon6 小时前
Docker 修改配置后无法启动问题
运维·docker·容器
阿猿收手吧!9 小时前
【Docker】Docker中卷的类型、区别及应用
开发语言·docker·容器·eureka
青啊青斯10 小时前
Windows搭建CUDA大模型Docker环境
windows·docker·容器
桂月二二12 小时前
基于Knative的无服务器引擎重构:实现毫秒级冷启动的云原生应用浪潮
云原生·serverless·knative
阿里云大数据AI技术12 小时前
阿里云 MaxCompute MaxQA 开启公测,解锁近实时高效查询体验
大数据·阿里云·云原生·实时数仓·maxcompute
茅坑的小石头12 小时前
CentOS系统docker配置镜像加速registry-mirrors,配置阿里云和道客
运维·docker·容器
喝水塞牙12 小时前
使用docker部署NextChat,使用阿里云、硅机流动、deepseek的apikey
阿里云·docker·容器