1. KubeSphere简介
KubeSphere 是在目前主流容器调度平台 Kubernetes 之上构建的企业级分布式多租户容器平台,提供简单易用的操作界面以及向导式操作方式,在降低用户使用容器调度平台学习成本的同时,极大减轻开发、测试、运维的日常工作的复杂度,旨在解决 Kubernetes 本身存在的存储、网络、安全和易用性等痛点。除此之外,平台已经整合并优化了多个适用于容器场景的功能模块,以完整的解决方案帮助企业轻松应对敏捷开发与自动化运维、微服务治理、多租户管理、工作负载和集群管理、服务与网络管理、应用编排与管理、镜像仓库管理和存储管理等业务场景。
更加详细的有关KubeSphere的介绍请参考:KubeSphere简介,功能介绍,优势,架构说明及应用场景
2. 在Kubernetes上最小化部署KubeSphere
2.1 部署要求
-
Kubernetes 版本必须为:v1.19.x,v1.20.x,v1.21.x,v1.22.x 或 v1.23.x(实验性支持);
$ kubectl version
-
机器满足最低硬件要求:CPU > 1 核,内存 > 2 GB;
$ lscpu # 查看cpu核数 $ free -h # 查看内存
-
在安装之前需配置 Kubernetes 集群中的默认存储类型(StorageClass)。
$ kubectl get sc
备注:如果kubernetes集群中没有默认的sc,可以按以下步骤进行配置。
step1 搭建nfs(NetWork File System 网络文件系统)服务器
# 在每个机器install nfs-utils
$ yum install -y nfs-utils
# 在kubernetes master节点执行以下命令
$ echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
# 执行以下命令,启动nfs服务,创建共享目录
$ mkdir -p /nfs/data
# 在kubernetes master执行
$ systemctl enable rpcbind
$ systemctl enable nfs-server
$ systemctl start rpcbind
$ systemctl start nfs-server
# 使配置生效
$ exportfs -r
#检查配置是否生效
$ exportfs
自动创建的 PV 以{namespace}-{pvcName}-{pvName}这样的命名格式创建在 NFS 服务器上的共享数据目录中,而当这个 PV 被回收后会以archieved-{namespace}-{pvcName}-{pvName}这样的命名格式存在 NFS 服务器上。要使用StorageClass,我们就得安装对应的自动配置程序,比如上面我们使用的是nfs,那么我们就需要使用到一个 nfs-client 的自动配置程序,我们也叫它 Provisioner,这个程序使用我们已经配置的nfs服务器,来自动创建持久卷,也就是自动帮我们创建PV。
step2 创建配置文件
## 创建一个文件defaultsc.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: 172.31.0.4 # 指定自己nfs服务器地址
- name: NFS_PATH
value: /nfs/data # nfs服务器共享的目录
volumes:
- name: nfs-client-root
nfs:
server: 172.31.0.4 # 指定自己nfs服务器地址
path: /nfs/data # nfs服务器共享的目录
---
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
step3 配置默认存储
# 配置默认存储
kubectl apply -f defaultsc.yaml
# 确认配置是否生效
kubectl get sc
备注:如何标注一个StorageClass为默认的?
和前面的步骤类似,你需要添加/设置注解 storageclass.kubernetes.io/is-default-class=true。
$ kubectl patch storageclass -p ‘{
“metadata”: {
“annotations”:{
“storageclass.kubernetes.io/is-default-class”:“true”}}}’
请注意,最多只能有一个 StorageClass 能够被标记为默认。 如果它们中有两个或多个被标记为默认,Kubernetes 将忽略这个注解, 也就是它将表现为没有默认 StorageClass。
2.2 部署准备
step1 去github下载相应的部署文件:
step2参考KubeSphere官网,根据需要修改cluster-configuration.yaml文件,指定需要开启的功能。(这一步可忽略)
2.3 部署安装
$ kubectl apply -f kubesphere-installer.yaml
$ kubectl apply -f cluster-configuration.yaml
2.4 卸载
执行Source code中scripts的kubesphere-delete.sh脚本,等待完成即可。