## LAB80 Dynamic Storage Provisioning ### Setup NFS 1. Create the shared directory: ```bash sudo mkdir -p /srv/nfs_share ``` 2. Set permissions ```bash sudo chown nobody:nogroup /srv/nfs_share sudo chmod 777 /srv/nfs_share ``` 3. Start NFS server ```bash # Use --network=host and omit the -p port mappings docker run -d \ --name nfs-server \ --privileged \ --restart unless-stopped \ --network=host \ -v /srv/nfs_share:/data:rw \ -e SHARED_DIRECTORY=/data \ -e PERMITTED_CLIENTS="*" \ itsthenetwork/nfs-server-alpine:12 ``` Check logs ```bash docker logs nfs-server ``` 4. Install NFS client packages on every node ```bash sudo apt update && sudo apt install nfs-common ``` >To test mounting the share >```bash >sudo mkdir -p /mnt/test_nfs4 >sudo mount -t nfs4 -o proto=tcp,port=2049 ><nfs_server_ip>:/ /mnt/test_nfs4 >``` --- **1. Add the official Helm repo** ```bash helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/ helm repo update ``` --- **2. Create namespace** ```bash kubectl create namespace nfs-provisioner ``` --- **3. Install using Helm (correct full command)** ```bash helm install nfs-provisioner \ nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \ --namespace nfs-provisioner \ --set nfs.server=<nfs_server_IP> \ --set nfs.path=<nfs_share> \ --set storageClass.name=nfs-client \ --set storageClass.create=true \ --set storageClass.defaultClass=false \ --set storageClass.onDelete=true ``` ### What each flag does: | Flag | Meaning | | ------------------------------------ | ----------------------------------- | | `--set nfs.server=` | NFS server IP address | | `--set nfs.path=` | Path exported by your NFS server | | `--set storageClass.create=true` | Automatically create a StorageClass | | `--set storageClass.name=nfs-client` | Name the SC `nfs-client` | | `--set storageClass.onDelete=true` | Cleanup subdir when PVC deleted | | `--namespace nfs-provisioner` | Clean isolation | --- **4. Verify installation** ### Pod: ```bash kubectl get pods -n nfs-provisioner ``` Should show: ``` nfs-provisioner-xxxxx 1/1 Running ``` ### StorageClass: ```bash kubectl get sc ``` Should show: ``` nfs-client k8s-sigs.io/nfs-subdir-external-provisioner ``` --- **5. Test with a PVC** Create `pvc.yaml`: ```yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-pvc spec: storageClassName: nfs-client accessModes: - ReadWriteMany resources: requests: storage: 1Gi ``` Apply: ```bash kubectl apply -f pvc.yaml kubectl get pvc ``` Expected: ``` STATUS: Bound ``` --- **6. Verify NFS directory creation** On your NFS server: ```bash ls -l /data/nfs ``` You will see: ``` default-test-pvc-xxxxx/ ``` ๐ That means **dynamic provisioning works**. --- Bonus: Make it the default StorageClass If you want this to be the default SC: ```bash kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' ``` ## Test - Filling up Storage Quota --- `storage-filler.yaml` ```yaml apiVersion: v1 kind: Pod metadata: name: storage-filler spec: containers: - name: filler image: busybox command: ["/bin/sh", "-c"] args: - | echo "Starting slow storage fill..." i=1 while true; do echo "Creating file $i..." dd if=/dev/urandom of=/data/file_$i.bin bs=100M count=1 2>&1 if [ $? -ne 0 ]; then echo "โ Write failed โ storage is FULL!" break fi i=$((i+1)) sleep 5 done echo "Sleeping so pod stays alive..." sleep 3600; volumeMounts: - name: vol mountPath: /data volumes: - name: vol persistentVolumeClaim: claimName: your-pvc-name ``` ### Replace: ``` your-pvc-name ``` with your real PVC name (the one that is 1 GB). --- # ๐งช How to Run This ### Apply PVC (example 1 GB) ```yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-pvc spec: storageClassName: nfs-client accessModes: - ReadWriteMany resources: requests: storage: 1Gi ``` Apply: ```bash kubectl apply -f pvc.yaml kubectl apply -f storage-filler.yaml ``` --- # What You Will Observe When PVC Becomes Full Your cluster will begin telling tales: ### 1. **dd write error** Inside container logs: ``` dd: writing 'file_11.bin': No space left on device โ Write failed โ storage is FULL! ``` ### 2. **Events on Pod** ```bash kubectl describe pod storage-filler ``` You may see: ``` No space left on device Failed to write Input/output error ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up