Lesson 1: Enterprise Kubernetes Architecture, VPC CNI & IRSA
๐ง The Concept (Explain Like Iโm 5)
Imagine building a high-tech hospital:
- The Medical Directors (The Control Plane):
kube-apiserver: The central reception desk. Every doctor, nurse, and patient must talk to the receptionist. Nobody talks to the database directly.etcd: The secure medical records vault. It is a distributed, high-speed key-value store that holds the complete truth of everything happening in the hospital.kube-scheduler: The triage coordinator. When a new patient arrives, the scheduler inspects every doctorโs workload and assigns the patient to the best available room.kube-controller-manager: The chief medical officer constantly walking the floor. If a room should have 3 nurses and one passes out, the controller immediately wakes up a backup nurse (Self-Healing).
- The Treatment Rooms (The Worker Nodes - Data Plane):
kubelet: The head nurse in each room. Talks to the central API server, pulls container images from the pharmacy, and starts containers.containerd: The sterile surgical tools that actually package and execute the patient processes.kube-proxy: The internal telephone exchange, routing network calls between rooms.
In AWS Elastic Kubernetes Service (EKS), AWS manages the entire Control Plane across 3 Availability Zones with a 99.95% uptime SLA. You only manage the Worker Nodes where your applications run.
๐ฌ Under the Hood: The Request Lifecycle of kubectl apply
What actually happens inside the cluster when an engineer executes kubectl apply -f deployment.yaml?
flowchart TD
User["๐จโ๐ป Engineer: kubectl apply"] --> Auth["1. Authentication & Authorization<br/>(TLS Cert / Webhook & RBAC)"]
Auth --> Mutate["2. Mutating Webhooks<br/>(Inject IRSA Tokens, Sidecars)"]
Mutate --> Schema["3. Schema & Resource Validation<br/>(OpenAPI Spec Check)"]
Schema --> Validate["4. Validating Webhooks<br/>(Kyverno / OPA Policy Guardrails)"]
Validate --> etcdCommit[("5. Atomic Commit to etcd<br/>(Record Saved)")]
etcdCommit -.-> Scheduler["6. kube-scheduler Watch Loop<br/>(Filters & Scores Nodes)"]
Scheduler --> Bind["7. Node Binding Recorded in etcd"]
Bind -.-> Kubelet["8. Kubelet PLEG Watch Loop on Node"]
Kubelet --> CRI["9. Container Runtime (containerd)<br/>Pulls Image from ECR"]
CRI --> CNI["10. AWS VPC CNI allocates IP & ENI"]
CNI --> Running["11. Pod Status: Running โ
"]
๐ The AWS VPC CNI Architecture Under the Hood
Standard Kubernetes networking uses Overlay Networks (like Flannel or Calico VXLAN). In an overlay network, Pods live in a virtual private subnet (e.g., 10.244.0.0/16) that is encapsulated inside outer UDP packets. AWS VPC switches, Security Groups, and ALB Load Balancers cannot see individual Pods directly.
The AWS VPC CNI (aws-node) completely re-engineers this:
- Every Pod receives a real, native, routable private IP address directly from your AWS VPC subnet.
- When an Application Load Balancer (ALB) receives an HTTP request, it routes traffic directly to the Podโs private IP, bypassing
NodePorthops and eliminating latency!
flowchart TD
subgraph EC2Node ["EC2 Worker Node (m6i.2xlarge)"]
subgraph ENI1 ["Primary Elastic Network Interface (eth0)"]
NodeIP["Node Private IP: 10.0.1.50"]
PodIP1["Pod IP: 10.0.1.51 (Secondary IP)"]
PodIP2["Pod IP: 10.0.1.52 (Secondary IP)"]
end
subgraph ENI2 ["Secondary ENI (eth1)"]
PodIP3["Pod IP: 10.0.1.61"]
PodIP4["Pod IP: 10.0.1.62"]
end
IPAMD["<b>aws-node (IPAMD Daemon)</b><br/>Manages warm IP pool via AWS EC2 API"]
end
IPAMD -->|"Attaches ENIs & IPs via AWS EC2 API"| AWS_EC2["AWS EC2 Metadata & Control Plane"]
The Enterprise Dilemma: Subnet IP Exhaustion
Because each Pod consumes an AWS VPC IP:
- An EC2 node with 30 pods consumes 31 IP addresses.
- A cluster with 20 nodes running 600 pods consumes 620 IP addresses!
- If your platform team only provisioned a
/24subnet (251 usable IPs), the cluster will crash withFailedCreatePodSandBox: no IP addresses available in subnet.
Enterprise Solutions:
- Secondary CIDR Blocks (CGNAT
100.64.0.0/16): Attach a non-routable carrier-grade NAT block (100.64.0.0/16or198.19.0.0/16) to your VPC specifically for Pod subnets. This preserves precious enterprise corporate IP space (10.0.0.0/8). - Prefix Delegation (
ENABLE_PREFIX_DELEGATION=true): Instead of allocating individual/32IP addresses to each ENI slot, AWS assigns a/28IPv4 prefix (16 IPs per slot). A singlem6i.xlargeinstance jumps from supporting 58 pods to over 110 pods!
Production Manifest 1: AWS VPC CNI DaemonSet Configuration (aws-node-env.yaml)
To deploy prefix delegation and warm IP optimization deterministically via GitOps (instead of imperative bash commands), patch the aws-node DaemonSet using the following production configuration:
# aws-node-cni-config.yaml - Production AWS VPC CNI Configuration
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: aws-node
namespace: kube-system
labels:
k8s-app: aws-node
spec:
template:
spec:
containers:
- name: aws-node
env:
# 1. Enable Prefix Delegation (/28 chunks = 16 IPs per allocation)
- name: ENABLE_PREFIX_DELEGATION
value: "true"
# 2. Prevent IP Hoarding: Keep exactly 1 warm prefix (/28) on standby
- name: WARM_PREFIX_TARGET
value: "1"
# 3. Micro-Tuning: Maintain warm individual Pod IPs to absorb sudden bursts
- name: WARM_IP_TARGET
value: "5"
# 4. Minimum IP Baseline per Node: Pre-allocate initial block on boot
- name: MINIMUM_IP_TARGET
value: "16"
# 5. Enable Custom Networking (Secondary CIDR routing for Pods)
- name: AWS_VPC_K8S_CNI_CUSTOM_NETWORK_CFG
value: "true"
# 6. Instruct CNI to read ENIConfig matching the node's Availability Zone
- name: ENI_CONFIG_LABEL_DEF
value: "topology.kubernetes.io/zone"
# 7. Disable Node SNAT for private subnets (Let AWS NAT Gateway handle egress)
- name: AWS_VPC_K8S_CNI_EXTERNALSNAT
value: "true"
# 8. Limit EC2 API call concurrency to avoid rate-limiting throttling
- name: WARM_ENI_TARGET
value: "0"
Production Manifest 2: Custom Networking CRD (ENIConfig)
When custom networking is enabled, secondary ENIs attached to worker nodes draw IPs from dedicated Pod subnets (e.g., Carrier-Grade NAT 100.64.0.0/16), isolating Pod IP consumption from primary EC2 host IPs (10.0.0.0/16):
# eniconfig-us-east-1a.yaml - Pod Network Allocation for AZ 1a
apiVersion: crd.k8s.amazonaws.com/v1alpha1
kind: ENIConfig
metadata:
name: us-east-1a # Matches node label topology.kubernetes.io/zone=us-east-1a
spec:
# Dedicated secondary Pod subnet in us-east-1a (100.64.10.0/20)
subnet: subnet-0123456789abcdef0
# Pod-specific Security Groups (enforces microsegmentation at pod network interface)
securityGroups:
- sg-0abcdef123456789a # Internal Pod Communication SG
- sg-0987654321fedcba0 # Shared EKS Cluster SG
---
# eniconfig-us-east-1b.yaml - Pod Network Allocation for AZ 1b
apiVersion: crd.k8s.amazonaws.com/v1alpha1
kind: ENIConfig
metadata:
name: us-east-1b # Matches node label topology.kubernetes.io/zone=us-east-1b
spec:
subnet: subnet-0fedcba9876543210 # Dedicated secondary Pod subnet in us-east-1b
securityGroups:
- sg-0abcdef123456789a
- sg-0987654321fedcba0
Detailed Breakdown of Key Fields & Architectural Mechanics:
ENABLE_PREFIX_DELEGATION: "true":- Mechanism: Replaces
/32individual secondary IP allocation with/28IPv4 prefix delegation. When an EC2 ENI attaches a prefix slot, AWS allocates a contiguous block of 16 IPv4 addresses. - Impact: On an
m6i.xlarge(max 4 ENIs, 15 IPs per ENI), standard mode caps node density at (4 ร (15 - 1)) + 2 = 58 Pods. With prefix delegation, capacity jumps to (4 ร 15 ร 16) = 960 IPs (clamped by Kubernetes max-pods standard sizing of 110 or 250).
- Mechanism: Replaces
WARM_PREFIX_TARGETvs.WARM_IP_TARGETBalance:- The Problem of IP Waste: Setting
WARM_PREFIX_TARGET=1withoutWARM_IP_TARGETtells the node to always hold 16 free IPs. If a node only has 1 Pod, it still holds 16 IPs. In a 50-node cluster, 800 IP addresses sit completely idle. - The Enterprise Solution: Setting
WARM_IP_TARGET=5andMINIMUM_IP_TARGET=16tellsipamdto keep a baseline of 16 IPs on node startup, but only acquire a new/28prefix when the available pool dips below 5 unassigned IPs. This strikes the perfect balance between zero pod launch latency and minimal VPC IP waste.
- The Problem of IP Waste: Setting
AWS_VPC_K8S_CNI_CUSTOM_NETWORK_CFG: "true":- Mechanism: Worker node primary interfaces (
eth0) remain inside the corporate corporate VPC CIDR (10.0.0.0/16) for bastion access, monitoring agents, and internal routing. - Pods on Secondary CIDR: All secondary interfaces (
eth1,eth2) attached to the node reside in the100.64.0.0/16secondary CIDR via the matchingENIConfigresource. Pods receive routable IPs within100.64.x.x, completely decoupling cluster scale from enterprise corporate IP exhaustion.
- Mechanism: Worker node primary interfaces (
AWS_VPC_K8S_CNI_EXTERNALSNAT: "true":- Mechanism: Disables node-level iptables SNAT for traffic bound outside the VPC. Traffic exiting to the public internet preserves the container IP until it hits the AWS NAT Gateway, avoiding conntrack table exhaustion on worker nodes.
๐ IAM Roles for Service Accounts (IRSA) vs. EKS Pod Identity
In early Kubernetes setups, engineers attached IAM policies to the Worker Node EC2 instance profile. This meant every single Pod on that node inherited full access to all cloud resourcesโa massive security violation.
1. IRSA (OpenID Connect Federation)
IRSA utilizes an OIDC Identity Provider tied to your EKS cluster:
- When a Pod with
serviceAccountName: payment-saboots, the EKS Pod Identity Webhook injects:AWS_ROLE_ARN: The target IAM role.AWS_WEB_IDENTITY_TOKEN_FILE: A projected service account JWT token signed by EKS private keys.
- The AWS SDK inside the container reads the token and calls
sts:AssumeRoleWithWebIdentity. - AWS STS validates the cryptographic signature against the EKS OIDC discovery endpoint (
oidc.eks.<region>.amazonaws.com) and returns temporary credentials valid for 1 hour.
sequenceDiagram
autonumber
participant Pod as ๐ฆ Application Pod (Payment Service)
participant Kubelet as ๐ก๏ธ Kubelet
participant API as โธ๏ธ EKS API & OIDC Provider
participant STS as โ๏ธ AWS STS (Security Token Service)
participant S3 as ๐๏ธ AWS S3 Bucket
Kubelet->>API: 1. Requests projected ServiceAccount JWT Token
API-->>Kubelet: 2. Signs JWT with EKS cluster private key
Kubelet->>Pod: 3. Mounts token at /var/run/secrets/eks.amazonaws.com/...
Pod->>STS: 4. AssumeRoleWithWebIdentity(JWT Token, Role ARN)
STS->>API: 5. Validates JWT signature against OpenID .well-known/jwks.json
STS-->>Pod: 6. Returns temporary AWS AccessKey, SecretKey & SessionToken
Pod->>S3: 7. S3 GetObject request using temporary STS credentials
S3-->>Pod: 8. Access Granted (200 OK) โ
2. EKS Pod Identity (Modern Standard - 2024+)
EKS Pod Identity replaces complex OIDC trust policy JSONs with a direct node-level agent:
- Runs as a daemonset (
eks-pod-identity-agent) listening on link-local address169.254.170.23:80. - The AWS SDK queries this local daemon directly, eliminating the need for cluster OIDC providers, mutating webhooks, and manual JWT token file projections!
๐ป Production Code: Provisioning IRSA with Terraform
1. Terraform IAM Role with OIDC Trust Relationship
# 1. Fetch EKS cluster OpenID Connect details
data "aws_iam_openid_connect_provider" "eks" {
arn = module.eks.oidc_provider_arn
}
# 2. Define IAM Policy for S3 access
resource "aws_iam_policy" "payment_s3_read" {
name = "PaymentServiceS3ReadPolicy"
description = "Allows payment service to read billing exports"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = ["s3:GetObject", "s3:ListBucket"]
Resource = [
"arn:aws:s3:::corp-payment-records",
"arn:aws:s3:::corp-payment-records/*"
]
}
]
})
}
# 3. Create IAM Role with OIDC Federation Trust Policy
resource "aws_iam_role" "payment_irsa" {
name = "payment-service-irsa-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Federated = data.aws_iam_openid_connect_provider.eks.arn
}
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
StringEquals = {
# Strictly scope to specific namespace and ServiceAccount name!
"${replace(data.aws_iam_openid_connect_provider.eks.url, "https://", "")}:sub" = "system:serviceaccount:workloads:payment-service-sa",
"${replace(data.aws_iam_openid_connect_provider.eks.url, "https://", "")}:aud" = "sts.amazonaws.com"
}
}
}
]
})
}
resource "aws_iam_role_policy_attachment" "payment_attach" {
role = aws_iam_role.payment_irsa.name
policy_arn = aws_iam_policy.payment_s3_read.arn
}
2. Kubernetes ServiceAccount & Deployment Manifest
apiVersion: v1
kind: ServiceAccount
metadata:
name: payment-service-sa
namespace: workloads
annotations:
# This annotation triggers the EKS Pod Identity Webhook
eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/payment-service-irsa-role
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: payment-service
namespace: workloads
spec:
replicas: 2
selector:
matchLabels:
app: payment-service
template:
metadata:
labels:
app: payment-service
spec:
serviceAccountName: payment-service-sa
containers:
- name: app
image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/payment:v1.4.2
resources:
requests:
cpu: "250m"
memory: "512Mi"
๐พ Enterprise Stateful Storage Architecture: AWS EBS CSI vs. EFS CSI (RWO vs. RWX)
Running stateless microservices in Kubernetes is simple; running stateful workloads (PostgreSQL, Kafka, Elasticsearch, Prometheus TSDB, Jenkins) requires mastering the Container Storage Interface (CSI).
flowchart TD
subgraph EBS_RWO ["AWS EBS CSI Driver (ReadWriteOnce - RWO)"]
PV_EBS["<b>EBS GP3 Volume (NVMe Block)</b><br/>โข Sub-millisecond latency<br/>โข Locked to Single AZ (e.g. us-east-1a)<br/>โข RWO: Only ONE Pod can mount at a time"]
PodA["Pod 1 (us-east-1a)"] -->|Direct NVMe Mount| PV_EBS
PodB["Pod 2 (us-east-1b)"] -.->|CANNOT MOUNT! Cross-AZ Blocked| PV_EBS
end
subgraph EFS_RWX ["AWS EFS CSI Driver (ReadWriteMany - RWX)"]
PV_EFS["<b>Amazon EFS FileSystem (NFS v4.1)</b><br/>โข Multi-AZ Elastic File System<br/>โข Accessible from all AZs simultaneously<br/>โข RWX: Dozens of Pods can mount concurrently"]
PodC["Pod 3 (us-east-1a)"] -->|NFS Mount| PV_EFS
PodD["Pod 4 (us-east-1b)"] -->|NFS Mount| PV_EFS
PodE["Pod 5 (us-east-1c)"] -->|NFS Mount| PV_EFS
end
1. Architectural Matrix: EBS GP3 vs. Amazon EFS
| Evaluation Dimension | AWS EBS CSI Driver (ebs.csi.aws.com) |
AWS EFS CSI Driver (efs.csi.aws.com) |
|---|---|---|
| Storage Protocol | Raw Block Device (NVMe SSD over PCIe) | Distributed Network File System (NFS v4.1 over TCP) |
| Kubernetes Access Mode | ReadWriteOnce (RWO): 1 Pod per volume |
ReadWriteMany (RWX): 100+ Pods concurrent read/write |
| Availability Zone Scope | Single AZ strictly. Cannot cross AZ boundaries! | Multi-AZ regional. Mounted across all subnets |
| Performance Profile | Ultra-Low Latency: Sub-millisecond, up to 16,000 IOPS | Elastic Throughput: 5โ15ms latency, scalable burst IOPS |
| Primary Workloads | High-performance DBs: PostgreSQL, Kafka, Redis, TSDB | Shared CMS (WordPress), ML training datasets, Jenkins workspace |
| Volume Attachment Limit | Nitro EC2 limits: ~28 EBS attachments per instance | Unlimited: Mounted via Linux kernel NFS client over ENI |
2. The Fatal Scheduling Trap: Immediate vs. WaitForFirstConsumer
In standard Kubernetes documentation, tutorials frequently omit the volumeBindingMode setting. In AWS, this triggers a cluster-wide scheduling deadlock:
The Disaster with volumeBindingMode: Immediate:
- You apply a PersistentVolumeClaim (PVC).
- The EBS CSI driver provisions a 100GB EBS volume immediately in
us-east-1abefore any pod is scheduled. - Your pod is created. However, your cluster has zero CPU capacity in
us-east-1a! Karpenter or Cluster Autoscaler spins up a new worker node inus-east-1b. - The Kubernetes scheduler attempts to place the pod on the new node in
us-east-1b. - The Crash: The scheduler detects that the PVC is locked to EBS in
us-east-1a. AWS EBS volumes cannot be attached across AZs! The pod enters a perpetual failure state:
Warning FailedScheduling: volume node affinity conflict (AZ mismatch).
The Architectural Mandate: WaitForFirstConsumer
Always declare volumeBindingMode: WaitForFirstConsumer on every production StorageClass:
- The CSI driver delays volume provisioning until the Kubernetes scheduler evaluates node capacity, taints, and affinities.
- Once the scheduler assigns the pod to a node in
us-east-1b, the EBS CSI driver provisions the EBS volume inus-east-1b, guaranteeing 100% AZ alignment!
3. Production Manifests: StorageClasses & StatefulSet
Production Manifest 1: AWS EBS GP3 StorageClass (storageclass-ebs.yaml)
# storageclass-ebs-gp3.yaml - High-Performance Block Storage with Dynamic Expansion
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ebs-gp3-sc
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer # MANDATORY: Prevents cross-AZ scheduling deadlocks!
allowVolumeExpansion: true # Allows online disk resizing without pod restarts!
reclaimPolicy: Retain # Protects production databases from accidental PVC deletion
parameters:
type: gp3
iops: "3000" # Baseline IOPS included at no extra cost
throughput: "125" # Baseline throughput (MB/s) included
encrypted: "true" # Mandatory enterprise encryption
Production Manifest 2: Amazon EFS RWX StorageClass (storageclass-efs.yaml)
# storageclass-efs-rwx.yaml - Shared Multi-Pod Storage across Availability Zones
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: efs-rwx-sc
provisioner: efs.csi.aws.com
volumeBindingMode: Immediate # EFS is Multi-AZ; safe to bind immediately
reclaimPolicy: Delete
parameters:
provisioningMode: efs-ap # Dynamically provisions EFS Access Points!
fileSystemId: fs-0123456789abcdef0 # Enterprise Regional EFS FileSystem ID
directoryPerms: "700"
gidRangeStart: "1000"
gidRangeEnd: "2000"
basePath: "/dynamic-pvc"
Production Manifest 3: StatefulSet with Online Dynamic Volume Expansion
# postgres-statefulset.yaml - Demonstrates StatefulSet & Online Volume Expansion
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres-primary
namespace: database
spec:
serviceName: postgres-service
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16-alpine
ports:
- containerPort: 5432
volumeMounts:
- name: pgdata
mountPath: /var/lib/postgresql/data
# Dynamic PVC template generated uniquely per StatefulSet replica
volumeClaimTemplates:
- metadata:
name: pgdata
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: ebs-gp3-sc
resources:
requests:
storage: 50Gi # Can be modified on-the-fly to 100Gi without pod downtime!
How Online Volume Expansion Operates Under the Hood:
- When disk utilization reaches 85%, an engineer (or autoscaling operator) edits the PVC:
storage: 100Gi. - The AWS EBS CSI Controller invokes the AWS EC2 API
ec2:ModifyVolume. - AWS expands the physical block volume dynamically in the background while NVMe I/O continues with zero downtime.
- Once AWS completes volume resizing, the Node CSI driver automatically executes the Linux filesystem resize tool (
xfs_growfsorresize2fs) inside the container host. - Storage expands to 100Gi with zero seconds of application downtime!
๐งญ Step-by-Step Operational Playbook: Production EKS Onboarding (IRSA, VPC CNI & Stateful CSI)
Follow this step-by-step operational runbook to configure a newly provisioned EKS cluster for enterprise production workloads:
Step 1: Verify Control Plane Access & Enable Prefix Delegation on AWS VPC CNI
- Plain-English Goal: Allow each Nitro worker node ENI to hold
/28IPv4 prefixes (16 IPs per slot instead of 1 IP), increasing pod density from ~29 pods to 110 pods per node. - Action:
aws eks update-kubeconfig --name prod-eks --region us-east-1 kubectl set env daemonset aws-node -n kube-system ENABLE_PREFIX_DELEGATION=true kubectl set env daemonset aws-node -n kube-system WARM_PREFIX_TARGET=1 kubectl rollout status daemonset/aws-node -n kube-system
Step 2: Bind a Pod ServiceAccount to an AWS IAM Role (IRSA / Pod Identity)
- Plain-English Goal: Never put
AWS_ACCESS_KEY_IDinside Kubernetes Secrets. Annotate the Kubernetes ServiceAccount so the kubelet mounts a short-lived OIDC token projected volume that exchanges viasts:AssumeRoleWithWebIdentity. - Action:
kubectl create namespace payments kubectl create serviceaccount payments-sa -n payments kubectl annotate serviceaccount payments-sa -n payments \ eks.amazonaws.com/role-arn="arn:aws:iam::111122223333:role/payments-s3-reader-role"
Step 3: Verify Token Projection Inside a Pod
- Plain-English Goal: Confirm the EKS Pod Identity Webhook mutated the pod spec to inject
AWS_WEB_IDENTITY_TOKEN_FILEandAWS_ROLE_ARN. - Action:
kubectl get pod -n payments -l app=payments-api -o yaml | grep -E "AWS_ROLE_ARN|AWS_WEB_IDENTITY_TOKEN_FILE"
Step 4: Install & Verify EBS CSI (WaitForFirstConsumer) and EFS CSI (RWX)
- Plain-English Goal: Use
gp3EBS volumes withWaitForFirstConsumerso single-node databases (ReadWriteOnce) always provision in the exact Availability Zone where the pod is scheduled, and EFS Access Points for shared multi-pod storage (ReadWriteMany). - Action:
kubectl get storageclass kubectl get csinodes kubectl get pvc -n payments
๐ ๏ธ Verification & Real-World Troubleshooting Guide
1. How to Verify IRSA is Actually Working
Run kubectl exec into the running container to inspect the injected environment variables:
# Check injected environment variables
kubectl exec -it deployment/payment-service -n workloads -- env | grep AWS
# Output:
# AWS_ROLE_ARN=arn:aws:iam::123456789012:role/payment-service-irsa-role
# AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
# Verify effective identity via AWS CLI inside the container
kubectl exec -it deployment/payment-service -n workloads -- aws sts get-caller-identity
# Output:
# {
# "UserId": "AROAXXXXXXXXXXXXXXXXX:botocore-session-1718000000",
# "Account": "123456789012",
# "Arn": "arn:aws:sts::123456789012:assumed-role/payment-service-irsa-role/botocore-session-..."
# }
2. The 3 Most Common IRSA Failures
| Error | Root Cause | How to Fix |
|---|---|---|
WebIdentityErr: failed to retrieve credentials: AccessDenied |
Typo in the OIDC condition string in the IAM trust policy (:sub mapping). |
Verify that the namespace and service account match exactly (system:serviceaccount:<namespace>:<sa-name>). |
AWS_ROLE_ARN variable missing inside container |
Pod was created before the ServiceAccount annotation was added, or mutating webhook failed. | Restart the pods (kubectl rollout restart deployment/<name>) so the webhook re-injects credentials. |
Pod Stuck in ContainerCreating: No available IP addresses |
Subnet CIDR is exhausted because Secondary CIDR or Prefix Delegation is disabled. | Turn on ENABLE_PREFIX_DELEGATION=true or allocate a secondary /16 CGNAT block to the VPC. |
๐ Knowledge Check & Enterprise Interview Scenarios
A developer suggests saving time by attaching an IAM policy with AdministratorAccess to the EKS Worker Node IAM Role (Instance Profile), arguing: โAll Pods running on these instances belong to our company anyway.โ
As a Platform Architect, why is this an immediate critical security failure? Provide 3 specific breach scenarios.
โ Answer & Explanation
Why it is a critical violation: It completely breaks the security principle of Least Privilege and destroys internal isolation.
Specific Breach Scenarios:
- SSRF (Server-Side Request Forgery) Vulnerability: If a public-facing frontend web container (e.g. WordPress, NGINX) suffers an SSRF vulnerability, an attacker can query the AWS Instance Metadata Service (
http://169.254.169.254/latest/meta-data/iam/security-credentials/) and steal full administrative AWS credentials, compromising the entire companyโs cloud. - Lateral Privilege Escalation Across Pods: An intern or contractor deploying a dev container in a separate namespace can access production databases, KMS encryption keys, and S3 buckets by inheriting the nodeโs permissions.
- Container Escape: If an attacker escapes a single container via a Linux kernel exploit, they gain root access to the EC2 host and all cloud infrastructure across all tenants on that node.
Your team is provisioning c6i.large instances (max 29 ENI IP addresses per instance). You have 40 lightweight microservices to schedule. Without Prefix Delegation, the Kubernetes scheduler refuses to place more than 29 pods on the node, leaving 60% of CPU and RAM idle.
Explain how Prefix Delegation solves this and what networking constraints must be respected.
โ Answer & Explanation
The Solution: Without Prefix Delegation, each ENI secondary slot holds a single /32 IP address (3 ENIs ร 10 IPs - 1 = 29 pods).
When ENABLE_PREFIX_DELEGATION=true is enabled, AWS allocates a /28 IPv4 CIDR block (16 contiguous IP addresses) to each slot. This increases capacity to over 110 pods per instance, allowing full utilization of node CPU and RAM.
Networking Constraints to Respect:
- Subnet Fragmentation: The subnet must have contiguous blocks of 16 IPs available. In heavily fragmented subnets, prefix allocation will fail.
- Kubelet Pod Limit: The
--max-podssetting on the kubelet must be explicitly tuned (using the Amazon EKSmax-pods-calculator.shscript) to allow scheduling more than the default 29 pods.