Sub topic 3
Persistent Volumes with EBS and EFS
Assume you know pods, Deployments, Services, namespaces, kubectl, YAML, IAM, VPCs, and EC2. This chapter focuses on the AWS integrations that keep an EKS cluster reliable and affordable.
Persistent Volumes with EBS and EFS
A PersistentVolume (PV) is storage that exists independently of a pod. A PersistentVolumeClaim (PVC) is a request for that storage. The EBS CSI driver provisions Amazon EBS volumes for pods.
EBS volumes provide block storage with good performance, but each volume is normally attached in one Availability Zone and mounted by one node at a time. Use them for databases and applications that need fast, single-writer storage.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ebs-gp3
provisioner: ebs.csi.aws.com
parameters:
type: gp3
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes: [ReadWriteOnce]
storageClassName: ebs-gp3
resources:
requests:
storage: 20GiWaitForFirstConsumer delays volume creation until Kubernetes schedules a pod. This helps place the volume in the pod's Availability Zone.
EFS provides regional, shared file storage. Multiple pods can mount it at the same time with ReadWriteMany. Choose EFS for shared files, accepting higher latency and a different cost model.
Scaling Pods and Nodes
A Horizontal Pod Autoscaler (HPA) changes replica counts from metrics such as CPU. Cluster Autoscaler changes node-group size. Karpenter provisions suitable EC2 nodes from pending pod requirements. Use requests and limits so schedulers can make useful decisions.
Logs and Metrics
Enable EKS control-plane logs when you need audit and troubleshooting data. CloudWatch Container Insights collects container logs, CPU, memory, and cluster metrics. Set retention periods and alerts instead of storing everything forever.
Hardening the Cluster
Use Kubernetes network policies to restrict pod traffic. Encrypt Kubernetes Secrets with AWS KMS. Give each workload only the IAM permissions it needs through IRSA or EKS Pod Identity. Keep the EBS and EFS CSI drivers updated.
Upgrading Kubernetes Versions Safely
Read the EKS version-support policy and add-on compatibility notes. Test in a staging cluster, upgrade one environment at a time, and verify nodes, workloads, CSI drivers, and admission policies. Keep multiple replicas and use disruption budgets for critical applications.
Keeping EKS Costs Under Control
EKS charges for the cluster control plane, while EC2, EBS, EFS, load balancers, and data transfer add separate costs. Right-size requests, remove unused volumes and load balancers, use managed node groups or Karpenter efficiently, and select Graviton or Spot capacity when workloads tolerate interruption.
Exercise
Which storage should you choose for two replicas on different nodes that must read and write the same files?
Show answer
EFS with the EFS CSI driver, because it supports shared ReadWriteMany access across nodes.