Amazon EKS — Storage Hands-On Lab

2 minute read

In this lab you’ll create StorageClasses, provision EBS volumes dynamically, test EFS shared storage, and create volume snapshots.


Prerequisites

  • Running EKS cluster with managed node group
  • EBS CSI Driver installed
  • EFS CSI Driver installed (for EFS section)
  • Snapshot controller installed (for snapshot section)

Part 1 — EBS gp3 StorageClass

Step 1 — Create the gp3 StorageClass

cat <<'EOF' | kubectl apply -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gp3-lab
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  fsType: ext4
  encrypted: "true"
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
allowVolumeExpansion: true
EOF

Step 2 — Create a PVC

cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ebs-test-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: gp3-lab
  resources:
    requests:
      storage: 5Gi
EOF

Note the PVC is Pending — WaitForFirstConsumer delays provisioning:

kubectl get pvc ebs-test-pvc
# STATUS: Pending

Step 3 — Deploy a Pod That Uses the PVC

cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: ebs-writer
spec:
  containers:
    - name: writer
      image: busybox
      command: ["sh", "-c", "echo 'Hello from EBS' > /data/hello.txt && sleep 3600"]
      volumeMounts:
        - name: ebs-vol
          mountPath: /data
  volumes:
    - name: ebs-vol
      persistentVolumeClaim:
        claimName: ebs-test-pvc
EOF

Step 4 — Verify

# PVC should now be Bound
kubectl get pvc ebs-test-pvc

# Verify the volume
kubectl get pv

# Check the data
kubectl exec ebs-writer -- cat /data/hello.txt

Part 2 — Volume Expansion

# Expand from 5Gi to 10Gi
kubectl patch pvc ebs-test-pvc -p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'

# Watch the expansion
kubectl describe pvc ebs-test-pvc | grep -A 5 Conditions

# Verify new size inside the pod
kubectl exec ebs-writer -- df -h /data

Part 3 — Volume Snapshots

Step 1 — Create a VolumeSnapshotClass

cat <<'EOF' | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
  name: ebs-snap-class
driver: ebs.csi.aws.com
deletionPolicy: Delete
EOF

Step 2 — Take a Snapshot

cat <<'EOF' | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: ebs-test-snapshot
spec:
  volumeSnapshotClassName: ebs-snap-class
  source:
    persistentVolumeClaimName: ebs-test-pvc
EOF
kubectl get volumesnapshot
kubectl describe volumesnapshot ebs-test-snapshot

Step 3 — Restore from Snapshot

cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ebs-restored-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: gp3-lab
  resources:
    requests:
      storage: 10Gi
  dataSource:
    name: ebs-test-snapshot
    kind: VolumeSnapshot
    apiGroup: snapshot.storage.k8s.io
---
apiVersion: v1
kind: Pod
metadata:
  name: ebs-reader
spec:
  containers:
    - name: reader
      image: busybox
      command: ["sh", "-c", "cat /data/hello.txt && sleep 3600"]
      volumeMounts:
        - name: restored-vol
          mountPath: /data
  volumes:
    - name: restored-vol
      persistentVolumeClaim:
        claimName: ebs-restored-pvc
EOF
# Verify restored data
kubectl logs ebs-reader
# Expected: Hello from EBS

Clean Up

kubectl delete pod ebs-writer ebs-reader
kubectl delete pvc ebs-test-pvc ebs-restored-pvc
kubectl delete volumesnapshot ebs-test-snapshot
kubectl delete volumesnapshotclass ebs-snap-class
kubectl delete storageclass gp3-lab

Updated: