Amazon EKS — Storage — Practice Exercises
Chapter 8 — Practice Exercises
Exercise 1: EBS vs EFS Decision
Question: You’re deploying a WordPress application on EKS with 3 replicas that all need to access the same uploaded media files. Should you use EBS or EFS? Explain your reasoning.
Show Solution
Use EFS.
Reasoning:
- WordPress uploads go to
/wp-content/uploads/ - 3 replicas need to read AND write to the same directory
- EBS is
ReadWriteOnce— only one pod can mount it - EFS is
ReadWriteMany— all 3 pods can read/write
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-uploads
spec:
accessModes:
- ReadWriteMany # All pods access same data
storageClassName: efs-sc
resources:
requests:
storage: 50Gi
Cost consideration: EFS is 3x more expensive than EBS, but it’s the only option for shared access across multiple pods.
Exercise 2: StorageClass Design
Question: Create a StorageClass for a production PostgreSQL database that needs: encrypted volumes, high IOPS (50,000), data preserved after PVC deletion, and proper AZ alignment.
Show Solution
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: postgres-storage
provisioner: ebs.csi.aws.com
parameters:
type: io2
iops: "50000"
encrypted: "true"
fsType: ext4
reclaimPolicy: Retain # Data preserved!
volumeBindingMode: WaitForFirstConsumer # AZ alignment!
allowVolumeExpansion: true # Can resize later
Key decisions:
io2for consistent high IOPS (gp3 maxes at 16,000)Retainso accidental PVC deletion doesn’t destroy dataWaitForFirstConsumerprevents AZ mismatchallowVolumeExpansionfor future growth
Exercise 3: StatefulSet
Question: Write a StatefulSet for a 3-replica Redis cluster where each replica needs its own 10Gi persistent volume. Include the headless Service.
Show Solution
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
clusterIP: None
selector:
app: redis
ports:
- port: 6379
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
serviceName: redis
replicas: 3
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:7
ports:
- containerPort: 6379
volumeMounts:
- name: data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: ebs-gp3
resources:
requests:
storage: 10Gi
Creates: redis-0, redis-1, redis-2 with PVCs data-redis-0, data-redis-1, data-redis-2.
DNS: redis-0.redis.default.svc.cluster.local
Exercise 4: Troubleshoot PVC
Question: A PVC is stuck in Pending status. List 5 common causes and how to diagnose each.
Show Solution
# First, check the PVC events
$ kubectl describe pvc <pvc-name>
5 common causes:
- No StorageClass exists:
$ kubectl get storageclass # Fix: Create the referenced StorageClass - EBS CSI driver not installed:
$ kubectl get pods -n kube-system -l app=ebs-csi-controller # Fix: Install the EBS CSI driver addon - IAM role missing permissions:
$ kubectl logs -n kube-system <ebs-csi-pod> -c ebs-plugin # Look for: "AccessDenied" errors - AZ mismatch (with Immediate binding):
$ kubectl describe pvc <name> | grep "waiting for first consumer" # Fix: Use WaitForFirstConsumer binding mode - Subnet has no nodes (WaitForFirstConsumer):
$ kubectl get nodes # If no nodes in the AZ, PVC waits forever # Fix: Ensure nodes exist in at least one AZ
Exercise 5: Storage Cost Optimization
Question: Your EKS cluster uses 50 × 100Gi gp3 EBS volumes at $0.08/GB/month = $400/month. 30 of these are for log storage pods that only need write performance. How would you reduce costs?
Show Solution
Option 1: Use st1 (throughput-optimized HDD) for log volumes:
30 × 100Gi × $0.045/GB = $135/month (vs $240)
Savings: $105/month (44%)
Option 2: Use EFS with Infrequent Access:
Hot data on EFS Standard: $0.30/GB
Old logs auto-tiered to IA: $0.016/GB
If 80% of logs are old: ~$0.07/GB effective
Option 3: Ship logs to S3 instead of storing on volumes:
S3 Standard: $0.023/GB/month
S3 IA: $0.0125/GB/month
Use Fluent Bit → S3 pipeline, no PVCs needed
Savings: ~$380/month (95%)
Recommended: Option 3 — ship logs to S3 via Fluent Bit, eliminate log PVCs entirely.
What’s Next?
Security: Chapter 9 — IAM & Security.