LAB11a: Dynamic Provisioning with StorageClass

LAB 50: Dynamic Provisioning with Storageclass

Let’s craft a clean, end-to-end guide that takes you from:

  1. Spinning up an NFS server in Docker

  2. Creating NFS-based PersistentVolume (PV) + StorageClass (SC)

  3. Enabling Dynamic Provisioning using NFS Subdir External Provisioner


##PART 1 — Create NFS Server in Docker

1️ Run an NFS server container

You can use the popular itsthenetwork/nfs-server-alpine image:

mkdir -p /srv/nfs
docker run -d --name nfs-server \
  --privileged \
  -v /srv/nfs:/nfsshare \
  -p 2049:2049 \
  -e SHARED_DIRECTORY=/nfsshare \
  itsthenetwork/nfs-server-alpine:latest

Check container logs:

Find server IP:

Suppose your NFS server IP is: 172.17.0.2.


PART 2 — Deploy NFS Subdir External Provisioner


2️ Create a Kubernetes namespace


** 3 Create the NFS Provisioner Deployment**

Create a file: nfs-provisioner.yaml

Apply it:


PART 3 — Create the StorageClass

4 Create StorageClass

Create file: nfs-storageclass.yaml

Apply it:


PART 4 — Test Dynamic Provisioning


5 Create a PVC

File: test-pvc.yaml

Apply:

You’ll see STATUS = Bound ✔️


6 Create a Pod that uses the PVC

File: test-pod.yaml

Apply:

Then check on the NFS server host:

You’ll see a shiny new folder named something like:

Inside it:


Summary

Component
Purpose

Docker NFS Server

Provides shareable storage

NFS Subdir External Provisioner

Auto-creates folder per PVC

StorageClass

Defines dynamic provisioning rules

PVC

Requests storage dynamically

Pod

Uses that dynamically created storage

Test - Filling up Storage Quota


** YAML: storage-filler.yaml**

Replace:

with your real PVC name (the one that is 1 GB).


How to Run This

Apply PVC (example 1 GB)

Apply:


What You Will Observe When PVC Becomes Full

Your cluster will begin telling tales:

1. dd write error

Inside container logs:

2. Events on Pod

You may see:

3. Application behavior

  • The pod will not crash, but the write loop exits

  • Your service may exhibit read-only behavior

  • Many apps crash when persistent disk becomes read-only

4. NFS / host logs

Depending on NFS backend, you may see disk pressure warnings.


Want the storage to fill even slower?

Change the speed:

Write 50 MB every 10 seconds:

Reference

Last updated