1. 环境查看
    系统环境
# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
# uname -a
Linux CentOS7K8SMaster01063 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

软件环境

# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698aa92f0b1", GitTreeState:"clean", BuildDate:"2019-02-28T13:37:52Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698aa92f0b1", GitTreeState:"clean", BuildDate:"2019-02-28T13:30:26Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
  1. 需求
    把一台NFS动态存储迁移至另外一台服务器
    原始主机IP地址和数据 192.168.3.63 /ifs/kubernetes/
    目标主机IP地址和数据 192.168.3.64 /ifs/kubernetes/
  2. 迁移步骤
    前提:已经安装好NFS并配置和原始配置一致
    迁移数据
/usr/bin/rsync -avzP -e "ssh -p 22" /ifs/kubernetes/ root@192.168.3.64:/ifs/kubernetes/

修改动态存储NFS配置文件

# kubectl edit deployment nfs-client-provisioner

Kubernetes怎么进行NFS动态存储迁移_数据


测试yaml文件

创建pvc

# cat test-claim.yaml 
apiVersion: v1
#创建pvc名称为test-claim
kind: PersistentVolumeClaim
metadata:
  name: test-claim
spec:
  #ReadWriteMany可读写并且可以被多个节点使用
  #ReadWriteOnce只能被一个节点使用
  #ReadOnlyMany可以被多个节点读取
  accessModes:
    - ReadWriteMany
  #对应的storageClass名
  storageClassName: "managed-nfs-storage"
  #定义动态分配存储空间大小为10M
  resources:
    requests:
      storage: 10Mi

创建pod该pod在pvc创建一个文件SUCCESS

# cat test-pod.yaml 
kind: Pod
apiVersion: v1
metadata:
  name: test-pod
spec:
  containers:
  - name: test-pod
    #image: busybox:1.24
    image: busybox
    command:
      - "/bin/sh"
    args:
      - "-c"
      - "touch /mnt/SUCCESS && exit 0 || exit 1"
    volumeMounts:
      - name: nfs-pvc
        mountPath: "/mnt"
  restartPolicy: "Never"
  volumes:
    - name: nfs-pvc
      persistentVolumeClaim:
        claimName: test-claim

创建另外一个pod挂载该文件至/mnt

# cat test-pod2.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: test-pod2
spec:
  containers:
  - name: nginx
    image: nginx
    volumeMounts:
      - name: nfs-pvc
        mountPath: "/mnt"
  volumes:
    - name: nfs-pvc
      persistentVolumeClaim:
        claimName: test-claim

创建成功在新的服务器文件夹下可以看到创建对应的目录

# ls -lah /ifs/kubernetes/