Quick Fix: Sharing Persistent Disks on Multiple Nodes in Kubernetes Using NFS
In this quick fix, I’ll show you how to use a single-write, multi-read persistent block storage(ie: Google Persistent Disk or Amazon Elastic Block Store Volume) to store data on multiple nodes in a Kubernetes cluster using NFS.
Introduction
When you create a Kubernetes cluster, you have a few options for storing data in your pods:
Use the ephemeral container storage
You can just store data directly in the disk available in your container when you start it. This data is ephemeral, and restarting the container will wipe that data from the container itself. This is perfectly fine for storing temporary data, but does not work for longer-term or persistent storage.
Persistent Bind-mount to the node where your container is running
You can store data more persistently by mounting to a shared directory on the server (node) your container is running on. When you develop in Docker locally, this is what you’re doing when you use the -v
flag in the docker run
command.
For example, the following command:
docker run -v ./app:/usr/src/app -t <my_container>`