Kubernetes 硬盘持久化之 NFS 使用

时间:2024-06-02 12:37:15

Kubernetes 硬盘持久化之 NFS 使用

NFS 定义和使用

NFS 全称是 Network File System (网络文件系统),即通过网络协议挂载一块远端的逻辑盘。

apiVersion: v1
kind: Pod
metadata:
  name: pod-nfs
  namespace: default
spec:
  containers:
    - name: container-nfs
      image: busybox
      imagePullPolicy: IfNotPresent
      command: ["/bin/sh"]
      args: ["-c","sleep 3600"]
      volumeMounts:
        - mountPath: /test
          name: test-volume
  volumes:
    - name: test-volume
      nfs:
        server: 192.168.31.60
        path: /nfs-test
root@k8s-master1:~# kubectl exec -it pod-nfs -- /bin/sh
/ # echo "hello world" > /test/test.txt
/ # exit
root@k8s-master1:~# cat /nfs-test/test.txt
hello world