Kubernetes Bare-Metal Dynamic Storage Allocation
In this documentation, we are going to set up Kubernetes dynamic storage provisioning on Bare-Metal using an NFS server.
Prerequisites.
- Kubernetes Cluster with at least 2 nodes
- Single instance NFS Server
- Basic Kubernetes and Networking Knowledge
Why Do this?
When working with storage its best to automate most of the complexities and let robots do what they do best, reduce our margins of ERROR.
These are some pros to moving to an external storage that dynamically provisions storage.
- Dynamic Storage Allocation:
i) No longer have to provision storage ahead of time
ii) No longer need to know which node the application needs to run and thus match it with the storage through node-affinity.
2. Scalability: The process of auto-scaling is solved with the decoupling of the storage from the application.
3. High Storage Availability: By having external storage separate from the Kubernetes environment, you can ensure availability and redundancy in the storage system. Also, the system will not succumb to failure on node failure.
4. Applications portability: By decoupling the storage from the application pod, you can have a more flexible application (Goodby to node-affinity rules)
5. Seamless Application Installs: For Helm installations and any other process that requires dynamic PVC, having dynamic storage allocation will save you a lot of headaches.
For this purpose we will need to:
- Set-up an NFS server
- We will have to set up an external NFS server that will then offer storage. (The NFS Server: Will use UNIX NFS protocol to mount persistent volumes.) - Set-Up Client Provisioner
- This is where we create a Kubernetes deployment on the cluster to ensure dynamic provisioning of storage.
Step 1: Set-up an NFS server
2. Set-Up Client Provisioner
In this step, we are going to deploy a single instance of NFS-provisioner in the Kubernetes cluster.
This will then be followed by the deployment of a Storage Class that will ensure the attachment of persistent volume claims.
Step 1: Deploy Access Control Rules
Create a rbac.yml file and copy the contents below into the file.
To deploy the configurations, run this command:
kubectl apply -f ./rbac.yml
Step 2: Create Storage Class
This storage class will be used to provision storage to the persistent volume claims that get created by pods.
Create a class.yml file and copy the contents below into the file:
To deploy the class configurations, run:
kubectl apply -f ./class.yml
Step 3: Create Nfs Provisioner Deployment
We will then proceed to install a single instance of the NFS storage provisioner. This pod will be responsible for the automation of memory allocation and the mounting of volumes.
Create a deployment.yml file and copy the contents below into the file:
To deploy the provisioner configurations, run:
kubectl apply -f ./deployment.yml
Step 4: Test Dynamic Storage
For this step, we will create a Persistent Volume Claim(PVC) and wait for it to get attached to dynamic storage allocate to it.
Create a test-pvc.yml file and copy the contents below into the file:
To create the volume claim, run:
kubectl apply -f ./test-pvc.yml
Conclusion
Hope you have learned something new and seen the advantages of having dynamic storage allocation for your Kubernetes deployments.
Feel free to leave a comment.