NFS

You can mount an network filesystem (NFS) to your Pod as nfs volume. Multiple Pods can mount and share the files in the same nfs volume. The data stored into nfs volume will be persistent across the Pod lifetime. You have to create your own NFS server before using nfs volume, and make sure the nfs-utils package is installed on Kubernetes minions.

Check whether your NFS server works before you go. You should check out the /etc/exports file with a proper sharing parameter and directory, and use the mount -t nfs <nfs server>:<share name> <local mounted point> command to check whether it could be mounted locally.

The configuration file of the volume type with NFS is similar to others, but nfs.server and nfs.path are required in the volume definition to specify NFS server information and the path mounted from. nfs.readOnly is an optional field for specifying whether the volume is read-only or not (the default is false):

# configuration file of nfs volume
$ cat 2-6-3_nfs.yaml
apiVersion: v1
kind: Pod
metadata:
name: nfs
spec:
containers:
-
name: nfs
image: ubuntu
volumeMounts:
- name: nfs
mountPath: "/data-mount"
volumes:
- name: nfs
nfs:
server: <your nfs server>
path: "/"

After you run kubectl create –f 2-6-3_nfs.yaml, you can describe your Pod with kubectl describe <pod name> to check the mounting status. If it's mounted successfully, it should show conditions. Ready as true and the target nfs you mount:

Conditions:
Type Status
Ready True
Volumes:
nfs:
Type: NFS (an NFS mount that lasts the lifetime of a pod)
Server: <your nfs server>
Path: /
ReadOnly: false

If we inspect the container with the docker command, we can see the volume information in the Mounts section:

"Mounts": [
{
"Source": "/var/lib/kubelet/pods/<id>/volumes/kubernetes.io~nfs/nfs",
"Destination": "/data-mount",
"Mode": "",
"RW": true
},
...
]

Actually, Kubernetes just mounts your <nfs server>:<share name> into /var/lib/kubelet/pods/<id>/volumes/kubernetes.io~nfs/nfs, and then mounts it into the container as the destination in /data-mount. You could also use kubectl exec to touch the file, to test whether it's perfectly mounted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.129.90