In Kubernetes (K8s), NFS (Network File System) is a commonly used network file sharing protocol that allows multiple computers to share a file system. In K8s, you can use NFS volumes to mount NFS shares into Pods so that file data can be shared between multiple Pods. The following are some usage scenarios of NFS volumes:
-
Shared configuration: Multiple applications or services may need access to the same configuration file. Using NFS volumes, configuration files can be stored on an NFS share and mounted into multiple Pods to ensure they all have access to the same configuration data.
-
Shared data: In some cases, data needs to be shared between multiple Pods, such as log files, uploaded files, etc. By mounting NFS shares to these Pods, data sharing and collaboration can be achieved.
-
Persistent storage: NFS volumes can be used as a persistent storage solution to retain data after Pods are rescheduled or restarted. This is useful for applications that require persistent data.
It is important to note that using NFS volumes requires ensuring network connectivity between the NFS server and the Kubernetes cluster, and permissions and security configurations should be properly considered.
Below is an annotated YAML example showing how to use NFS volumes with Kubernetes:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: container1
image: nginx
volumeMounts:
- name: nfs-data
mountPath: /data
volumes:
- name: nfs-data
nfs:
server: nfs-server.example.com
path: /exports/data
In this example, container1
the container uses an NFS volume to mount the directory nfs-server.example.com
on the NFS server /exports/data
to the path in the Pod /data
. This way, container1
file data on the NFS share can be accessed and manipulated.
server
Please make sure to replace the values of and path
with the real NFS server address and share path when actually using them .