K8s之KubeSphere平台部署

  KubeSphere是一个分布式操作系统,提供以Kubernetes为核心的云原生堆栈,旨在成为第三方应用程序的即插即用架构,以促进其生态系统的发展。 KubeSphere还是一个多租户企业级容器平台,具有全栈自动IT操作和简化的DevOps工作流程。它提供了开发人员友好的向导Web UI,可帮助企业构建更健壮且功能丰富的平台,其中包括企业Kubernetes战略所需的最常用功能,例如Kubernetes资源管理,DevOps(CI / CD),应用程序生命周期管理、监控、日志记录、服务网格、多租户、报警和通知,存储和网络、自动定量、访问控制、GPU的支持等,以及多集群管理、网络策略、注册表管理,更多即将发布的安全增强特性。

KubeSphere提供了整合的视图,同时围绕Kubernetes集成了广泛的生态系统工具,并提供一致的用户体验以降低复杂性,并开发了上游Kubernetes中尚不可用的新功能,以减轻Kubernetes的痛苦之处,包括存储,网络 ,安全性和易用性。 KubeSphere不仅允许开发人员和DevOps团队在统一控制台中使用他们喜欢的工具,而且最重要的是,由于这些功能是可插拔和可选的,因此它们与平台松散地结合在一起。

Kubernetes平台,专为DevOps团队量身定制

KubeSphere,以应用为中心的容器平台

极简、易用、灵活、高效


在k8s集群上安装部署

软硬件要求
Kubernetes 版本必须为 “1.15.x,1.16.x,1.17.x 或 1.18.x”;
确保您的计算机满足最低硬件要求:CPU > 1 核,内存 > 2 G;
在安装之前,需要配置 Kubernetes 集群中的默认存储类;

配置k8s默认存储类(StorageClass)
 要使用 StorageClass,我们就得安装对应的自动配置程序,比如我们这里存储后端使用的是 nfs,那么我们就需要使用到一个 nfs-client 的自动配置程序,我们也叫它 Provisioner,这个程序使用我们已经配置好的 nfs 服务器,来自动创建持久卷,也就是自动帮我们创建 PV。
第一步:搭建一个nfs服务器,创建共享目录。

选定一台nfs服务器,我这里ip为:192.168.47.50
创建共享目录:
mkdir -pv /data/nfs-share/k8s
chmod 666 /data/nfs-share/k8s
安装nfs:
yum install nfs-utils rpcbind -y
vim /etc/exports
/data/nfs-share/k8s 192.168.47.0/24(rw)

systemctl start nfs

exportfs -v  查看本机所有NFS共享
exportfs -r  重读配置文件,并共享目录

在k8s节点检查并挂载nfs:
showmount -e 192.168.47.50
mount -t nfs 192.168.47.50:/data/nfs-share/k8s /data/nfs-share/k8s

第二步:创建一个独立的storgeclass,为nfs-client-provisioner创建一个serviceAccount,然后绑定上对应的权限。

cat rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: storgeclass
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update","create"]
  - 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: storgeclass
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: storgeclass
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: storgeclass
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: storgeclass
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io
[root@k8s-master storgeclass]# cat rbac.yaml 
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: storgeclass
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update","create"]
  - 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: storgeclass
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: storgeclass
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: storgeclass
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: storgeclass
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

应用创建:kubectl apply -f rbac.yaml

第三步:配置 Deployment,将里面的对应的参数替换成我们自己的 nfs 配置(nfs-client.yaml)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: storgeclass
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: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 192.168.47.50
            - name: NFS_PATH
              value: /data/nfs-share/k8s
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.47.50
            path: /data/nfs-share/k8s

应用并验证:

kubectl get pod -n storgeclass
storgeclass                    nfs-client-provisioner-78c8fdf8fc-zn76k                  1/1     Running   0          4h18m

第四步:创建默认存储类

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
  archiveOnDelete: "false"

其中 annotations 下面的 storageclass.kubernetes.io/is-default-class: “true” 是必须的:

[root@k8s-master storgeclass]# kubectl get sc
NAME                            PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
managed-nfs-storage (default)   fuseim.pri/ifs   Delete          Immediate           false                  4h26m

部署 KubeSphere
执行下面yaml文件:

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

检查安装日志:

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

安装成功可以看见最终下面结果:
在这里插入图片描述
确认pod启动情况:
在这里插入图片描述
最后确保在安全组中打开了端口 30880,并通过 NodePort(IP:30880)使用默认帐户和密码(admin/P@88w0rd)访问 Web 控制台。
在这里插入图片描述
浏览器登录:
在这里插入图片描述
验证使用:
在这里插入图片描述

### Ubuntu 上搭建 Kubernetes 集群并部署 KubeSphere 平台 #### 准备工作 为了确保顺利安装,在开始之前需确认系统环境已准备好。对于Ubuntu系统,建议先更新软件源列表并升级现有包。 ```bash sudo apt-get update && sudo apt-get upgrade -y ``` #### 安装 CRI-Dockerd 由于Kubernetes不再支持原生Docker作为容器运行时,因此需要安装`cri-dockerd`来兼容旧版应用[^2]。 1. 下载适用于Ubuntu系统的`.deb`包: ```bash wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.4/cri-dockerd_0.3.4.3-0.ubuntu-focal_amd64.deb ``` 2. 使用 `dpkg` 命令完成安装: ```bash sudo dpkg -i cri-dockerd_0.3.4.3-0.ubuntu-focal_amd64.deb ``` 3. 修改服务启动参数以适应CNI网络插件的要求: ```bash sudo sed -i -e 's#ExecStart=.*#ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint unix:///var/run/cri-dockerd.sock --network-plugin cni#g' /lib/systemd/system/cri-docker.service ``` 4. 启动并启用该服务: ```bash sudo systemctl daemon-reload sudo systemctl enable cri-dockerd sudo systemctl start cri-dockerd ``` #### 初始化 Kubernetes 主节点 接下来按照官方文档指导进行主控节点初始化操作。这里假设读者已经熟悉了基本概念以及相关命令行工具的使用方法。 ```bash sudo kubeadm init --pod-network-cidr=10.244.0.0/16 ``` 此过程会生成一系列用于加入其他worker节点所需的token信息,请妥善保存以便后续步骤中使用。 #### 设置kubectl认证配置 为了让当前用户能够管理新创建出来的集群,还需要复制管理员证书到默认路径下,并设置相应的环境变量。 ```bash mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config ``` #### 安装 Pod 网络附加组件 (Flannel) 只有当Pod之间可以互相通信之后才能继续下一步骤;推荐采用Calico或Weave Net等方案实现跨主机间的Layer 2/Layer 3连通性。 ```bash kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml ``` 等待几分钟直到所有核心组件都处于正常状态(`Running`)为止。 #### 部署 KubeSphere 控制面板 现在万事俱备只欠东风——通过YAML定义文件一键式安装企业级PaaS平台! 1. 创建必要的命名空间和服务账户对象: ```yaml apiVersion: v1 kind: Namespace metadata: name: kubesphere-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: ks-admin-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: default namespace: kubesphere-system ``` 2. 应用上述资源描述符至目标环境中: ```bash kubectl apply -f - ``` 3. 获取最新的稳定发行版本号: ```bash export VERSION=$(curl -L -s https://get.kubesphere.io/simple | grep "latest version" | awk '{print $NF}') echo ${VERSION} ``` 4. 执行实际安装动作: ```bash ./kk create config --with-kubesphere=${VERSION} config-sample.yaml kubectl apply -f kk/kustomize/ ``` 5. 实时跟踪整个流程的状态变化情况: ```bash watch kubectl get pods -n kubesphere-system ``` 一旦看到所有的Pod均进入就绪阶段,则表示成功完成了全部准备工作。此时可以通过浏览器访问<http://Master_IP:30080>页面来进行图形化的向导式体验啦!默认超级管理员账号为admin/Kuboard123[^5]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值