NFS Migration – Migrating PVC's to a New NFS Server
This document explains how to migrate all existing Persistent Volume Claim (PVC) data from an old NFS server to a new NFS server, and reconnect your Kubernetes cluster to the new NFS node.
Prerequisites
Steps to perform NFS migration
/srv/nfs/openg2p/<env-name>
kubectl scale deploy --all -n <namespace> --replicas=0 kubectl scale statefulset --all -n <namespace> --replicas=0
rsync -aADEHU [email protected]:/srv/nfs/openg2p/<folder-name> /srv/nfs/<folder-name> example: rsync -aADEHU [email protected]:/srv/nfs/openg2p/openg2p /srv/nfs/openg2p
#!/usr/bin/env bash if [ -z "$NEW_NFS_SERVER_IP" ]; then echo "New server IP required!!" exit 1 fi if [ -z "$TMP_PV_YAML_PATH" ]; then export TMP_PV_YAML_PATH=/tmp/move-pv.yaml fi # 👇 Add the namespaces you want to patch NAMESPACES="<provide the namespace name>" sleep 10 for ns in $NAMESPACES; do echo "===== Processing namespace: $ns =====" PV_LIST=$(kubectl get pv -o jsonpath="{range .items[?(@.spec.claimRef.namespace=='$ns')]}{.metadata.name}{'\n'}{end}") for pv in $PV_LIST; do echo "patching pv started --- $pv" [ -f $TMP_PV_YAML_PATH ] && rm $TMP_PV_YAML_PATH kubectl get pv $pv -oyaml > $TMP_PV_YAML_PATH # Update NFS server sed -i "s/server:.*/server: $NEW_NFS_SERVER_IP/g" $TMP_PV_YAML_PATH # Update volumeHandle IP only sed -i "s/[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}#/${NEW_NFS_SERVER_IP}#/g" $TMP_PV_YAML_PATH kubectl delete pv/$pv & delete_pid=$! sleep 1 kubectl patch pv/$pv --type json \ --patch='[{"op": "remove", "path": "/metadata/finalizers"}]' if [ $? -eq 0 ]; then wait $delete_pid kubectl apply -f $TMP_PV_YAML_PATH fi echo "patching pv done --- $pv" done doneexport NEW_NFS_SERVER_IP=<NEW NFS IP> ./updatepv.sh
Last updated
Was this helpful?

