数据迁移-kubernetes使用openebs场景

数据迁移-kubernetes使用openebs场景

说明

kubernetes使用openebs时,若使用kubekey或者其他工具部署,存在未配置指定目录的情况,默认数据存放在/var/openebs/local,当POD使用pvc和pv时,持久存储的数据会打爆根目录,导致work node异常。可参考本方法进行数据迁移。

可以先参考基础配置,检查集群是否存在其他需要调整的地方,https://blog.csdn.net/2502_92174648/article/details/162232663?spm=1011.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--replicas=0kubectl 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--replicas=1# 确认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名字是work1,2,3 ,你应当把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

查看pod

kubectl 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.binbs=1Mcount=10240&donewaitecho"所有数据写入完成"

验证写入结果。在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