数据迁移-kubernetes使用openebs场景

发布时间:2026/7/2 8:43:21
数据迁移-kubernetes使用openebs场景 说明kubernetes使用openebs时若使用kubekey或者其他工具部署存在未配置指定目录的情况默认数据存放在/var/openebs/local当POD使用pvc和pv时持久存储的数据会打爆根目录导致work node异常。可参考本方法进行数据迁移。可以先参考基础配置检查集群是否存在其他需要调整的地方https://blog.csdn.net/2502_92174648/article/details/162232663?spm1011.2415.3001.5331特殊说明本文假设所有work node都配置了openebs且所有work node都出现了存储爆满的风险。注意openebs的数据存储配置仅用于work node不会用于master node。所以仅配置work node定制集群除外。准备磁盘因先前已有大容量磁盘且挂载目录/data空间足够。此处不做展示。关停组件在master node1 操作# 停止pvc的功能kubectl scale deployment openebs-localpv-provisioner-nkube-system--replicas0kubectl get pods-nkube-system|grepopenebs-localpv-provisionermkdir/data/backup# 备份storageclass配置文件kubectl get sclocal-oyaml/data/backup/sc-local-backup.yaml在所有work node操作# 关组件systemctl stop kubelet备份数据在所有work node操作mkdir/data/backup# 同步数据到新位置特殊注意若遇到warring提示务必再次同步一次。rsync-avz/var/openebs/ /data/openebs# 将旧数据备份到新位置mv/var/openebs /data/backup/openebs调整配置在所有work node操作。# 配置软链接规避配置缺失导致的找不到数据问题ln-s/data/openebs /var/openebsls-l/var/openebs# 启动组件systemctl start kubelet在master node1操作注意必须在所有work node完成前置操作才能进行此处# 修改storageclass的配置kubectl edit sclocal# 将/var/openebs/local改为/data/openebs/local# 开启pvc调度功能kubectl scale deployment openebs-localpv-provisioner-nkube-system--replicas1# 确认POD存在kubectl get pods-nkube-system|grepopenebs-localpv-provisioner测试验证测试确认数据调整后的存储可以正常使用。确认node都正常。在master node1操作kubectl getnode-A-owide确认POD都正常访问有数据持久化配置的POD查看数据是否还在。在master node1操作kubectl get pode-A-owide检查storageclass。在master node1操作kubectl get storageclass-A# 注意当前环境只有local以环境真实情况为准kubectl get storageclasslocal-oyaml kubectl describe storageclasslocal确认磁盘空间状态。在所有work node操作务必记录。df-h/datadf-h/var创建测试专用namespace。在master node1操作kubectl create ns storage-test创建资源文件local-storage-test.yaml。在master node1操作注意我的环境storageclass名字是local你应当查询改为你的。我的环境work node名字是work123 你应当把kubernetes.io/hostname:部分改为你的环境使用的。# local-storage-test-fixed.yamlapiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-pvc-1 namespace: storage-test spec: accessModes: - ReadWriteOnce storageClassName:localresources: requests: storage: 12Gi --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-pvc-2 namespace: storage-test spec: accessModes: - ReadWriteOnce storageClassName:localresources: requests: storage: 12Gi --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-pvc-3 namespace: storage-test spec: accessModes: - ReadWriteOnce storageClassName:localresources: requests: storage: 12Gi --- apiVersion: v1 kind: Pod metadata: name: test-pod-1 namespace: storage-test spec: nodeSelector: kubernetes.io/hostname: work1 containers: - name: writer image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/busybox:1.38.0 command:[sleep,infinity]volumeMounts: - name:>[sleep,infinity]volumeMounts: - name:>[sleep,infinity]volumeMounts: - name:>kubectl apply-flocal-storage-test.yaml查看podkubectl get all-nstorage-test-owide查看pvc。在master node1操作kubectl get pvc-nstorage-test查看pod。在master node1操作kubectl get pod-nstorage-test-owide给三个pod写入数据。在master node1操作foriin123;doecho开始向 test-pod-$i写入10GB数据...kubectlexec-nstorage-test test-pod-$i--ddif/dev/zeroof/data/test-10g.binbs1Mcount10240donewaitecho所有数据写入完成验证写入结果。在master node1操作foriin123;doecho test-pod-$i数据校验 kubectlexec-nstorage-test test-pod-$i--ls-lh/data/test-10g.bin kubectlexec-nstorage-test test-pod-$i--du-sh/data/test-10g.bindone确认磁盘空间状态。在所有要测试的work node操作务必记录。df-h/datadf-h/var预期结果/data数据增加/var无变化。清理测试资源。在master node1操作kubectl delete-flocal-storage-test.yaml kubectl delete ns storage-test kubectl get pvc-A|greptestkubectl getpv|greppvc再次查看确认10GB空间已被释放。确认磁盘空间状态。在所有要测试的work node操作务必记录。df-h/datadf-h/var