- 環境檢視
系統環境
# 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"}
-
需求
把一臺NFS動態儲存遷移至另外一臺伺服器
原始主機IP地址和資料 192.168.3.63 /ifs/kubernetes/
目標主機IP地址和資料 192.168.3.64 /ifs/kubernetes/ -
遷移步驟
前提:已經安裝好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
測試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/