Sub topic 3
Pod Networking in a VPC
This chapter assumes you know what a VPC, a subnet and an elastic network interface (ENI) are, and that you can run kubectl commands.
Pods Get Real VPC Addresses
Many Kubernetes clusters hide pods behind an overlay network. EKS does not. The Amazon VPC CNI plugin gives each pod a private IP address from your VPC subnet. A pod is therefore a first-class VPC citizen. Security groups, route tables, flow logs and other VPC resources see the pod's own address, and no encapsulation is involved.
The plugin runs as the aws-node DaemonSet in kube-system. On each node it attaches ENIs to the instance and keeps a pool of secondary IP addresses on them. When the kubelet starts a pod, the plugin takes an address from the pool and wires it to the pod's network namespace.
Pods Per Node Are Limited by ENIs
An instance type allows a fixed number of ENIs, and each ENI allows a fixed number of IPv4 addresses. The default maximum number of pods is:
ENIs × (IPs per ENI − 1) + 2
For an m5.large, which supports 3 ENIs with 10 addresses each, that is 3 × 9 + 2 = 29 pods. The cluster in this tutorial would therefore hold at most 58 pods on its two nodes, however much CPU is free.
You can check the limit a node reports:
kubectl get nodes -o custom-columns=NAME:.metadata.name,MAXPODS:.status.allocatable.podsPrefix Delegation
If the limit is too low, enable prefix delegation. The plugin then assigns a /28 block (16 addresses) to each ENI slot instead of a single address, which raises the pod count. Set it on the DaemonSet:
kubectl set env daemonset aws-node -n kube-system ENABLE_PREFIX_DELEGATION=trueThis applies to nodes launched afterward, and the node's maximum pod setting must also allow the larger number. Your subnets need contiguous free /28 blocks, which fragmented subnets may lack.
Common Errors
- Pods stuck in
ContainerCreating. The event log often shows a failure to assign an IP address. Either the node has used up its pool or the subnet has no free addresses. - Subnet exhaustion. Every pod consumes a subnet address. A small /24 subnet fills quickly, so size node subnets generously. If you cannot, custom networking lets pods use addresses from a separate secondary CIDR.
- Pending pods despite free CPU. The node has hit its pod limit, not its resource limit. Check the calculation above.
- Unexpected source addresses. Traffic leaving the VPC is source-NATed to the node's address by default. Traffic inside the VPC keeps the pod IP.
Related Controls
The same design lets you attach security groups directly to pods. It also allows Kubernetes network policies, which the Security chapter covers. Because pods are VPC addresses, a database security group can allow traffic from a pod's group, not from every node.
Exercise
A node's instance type supports 4 ENIs with 15 IPv4 addresses each. How many pods can it run by default, and what feature would raise that limit?
Show answer
4 × (15 − 1) + 2 = 58 pods. Prefix delegation raises it by assigning /28 prefixes instead of single addresses.
Exercise
Pods are Pending on a node with idle CPU, and a new pod's events mention failing to assign an IP address. Name two likely causes.
Show answer
The node reached its ENI-based pod limit, or the subnet has run out of free IP addresses.