Recycle下的nfs的pvc迁移


Recycle下的nfs的pvc恢复

环境说明

老nfs: 10.0.2.4 新nfs: 192.168.0.22

现在需要修改nfs的sc从老nfs迁移到新nfs。

应用: test-aaa 挂载了pvc: test-aaa

nfs的文件同步

略 通过rync同步老nfs的文件到新的nfs文件

创建新的sc

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-client-sc
provisioner: xxxx.com/nfs-provisioner
parameters:
  archiveOnDelete: "false"

修改deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: nfs-client-provisioner
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: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: xxxx.com/nfs-provisioner
            - name: NFS_SERVER
              value: 192.168.0.22
            - name: NFS_PATH
              value: /data/nfs/kubernetes
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.0.22
            path: /data/nfs/kubernetes

备份pvc和pv文件

kubectl get pvc xxxx -o yaml > xxx-pvc.yaml
kubectl get pv xxxx -o yaml > xxx-pv.yaml

删除应用的相关文件

kubectl delete deployment aaa
kubectl delete pvc xxxx

修改pvc,pv文件,重新创建pvc

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: xxxx.com/nfs-provisioner
  name: pvc-c46e56f3-0279-46c5-ac4e-507ce224d339
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 50Gi
  claimRef:
    name: xxxx
    namespace: default
  nfs:
    path: /data/nfs/kubernetes/default-xxxx-pvc-c46e56f3-0279-46c5-ac4e-507ce224d339
    server: 192.168.0.22
  persistentVolumeReclaimPolicy: Delete
  storageClassName: nfs-client-sc
  volumeMode: Filesystem

创建pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: xxxx
  namespace: ci
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 50Gi
  storageClassName: nfs-client-sc
  volumeMode: Filesystem
  volumeName: pvc-c46e56f3-0279-46c5-ac4e-507ce224d339

创建应用

kubectl apply -f xxx.yaml

拓展

如果是PVC是Delete策略,做好备份策略。如果备份没有,删除了pvc,就自求多福了。