背景:通常情况下,KubeSphere安装会有默认存储(local);而实际业务可能需要使用到不同的存储。以下操作为在已有的KubeSphere环境下添加别的存储,如(nfs)。通过前期准备、拷贝脚本、拷贝脚本至合适的位置、执行脚本安装和检查是否成功5步介绍,添加使K8s能动态持久化的存储。
大致原理:存储服务端需用户自己搭建,然后在conf下配置文件中修改对应存储的参数;存储的客户端脚本已处理;以下脚本运行成功之后会创建对应存储的sc,可为pod动态提供持久化的存储和KubeSphere的ui界面会显示存储。
前期准备
进入到KubeSphere解压之后的安装介质目录conf下,有三个文件,而我们需要关注的是common.yaml和plugin-qingcloud.yaml。当使用青云的csi时,修改plugin-qingcloud.yaml即可;当使用nfs、gluster或者ceph时,修改common.yaml即可,具体参数参考官网的说明持久化存储配置说明。
以下以nfs存储为例说明,nfs_client_enabled修改为true,nfs_client_is_default_class保持原样,nfs_server对应的nfs服务端的IP,nfs_path服务端挂载路径等信息即可;nfs服务端搭建可以参考官网或者
类似文档nfs搭建。
nfs_client_enabled: true
nfs_client_is_default_class: false
# Hostname of the NFS server(ip or hostname)
nfs_server: 192.168.12.2
# Basepath of the mount point
nfs_path: /nfsdatas
拷贝脚本
- 脚本分别为:install-storage.sh和storage.yml两个文件。
curl -L https://kubesphere-installer.pek3b.qingstor.com/shareTools/software-lin/install-storage.sh > install-storage.sh
curl -L https://kubesphere-installer.pek3b.qingstor.com/shareTools/software-lin/storage.yml > storage.yml
拷贝脚本至合适的位置
- 把storage.yml文件拷贝至KubeSphere解压之后的安装介质目录kubesphere下,如所示
[root@master scripts]#ls
check_version.yml config kubesphere.yml roles scale.yml storage.yml upgrade.yml
[root@master kubesphere]# pwd
/root/kubesphere-all-v2.1.0/kubesphere
- 把install-storage.sh文件拷贝至KubeSphere解压之后的安装介质目录scripts下,如所示
[root@master scripts]#ls
add-nodes.sh ansible.cfg install.sh install-storage.sh os uninstall.sh upgrade.sh
[root@master scripts]# pwd
/root/kubesphere-all-v2.1.0/scripts
执行脚本安装
- 进入安装目录,建议使用 root 用户执行 install-storage.sh 安装脚本:
chmod +x install-storage.sh && ./install-storage.sh
检查是否成功
- 检查sc是否存在和检查对应存储pod是否running两项。
kubectl get sc
NAME PROVISIONER AGE
local (default) openebs.io/local 2d1h
nfs-client cluster.local/nfs-client-nfs-client-provisioner 58m
[root@master scripts]# kubectl get pod --all-namespaces | grep nfs
kube-system nfs-client-nfs-client-provisioner-f994fc69-h284f 1/1 Running 0 59m