Sub topic 3
Pod Networking in a VPC
This chapter assumes you know what a pod and a Service are, and that you can read a VPC layout: subnets, CIDR blocks, route tables and security groups. It also assumes you can run kubectl against a cluster. You don't need a cluster yet. The next chapter creates one, and this chapter explains the networking that cluster will use.
Pods Get Real VPC IP Addresses
Many Kubernetes networks put pods on an overlay network, a private address space that is tunneled between nodes. EKS does not do this by default. The Amazon VPC CNI plugin gives every pod an IP address taken from the VPC subnet the node lives in. CNI stands for Container Network Interface, the plugin standard Kubernetes uses to wire up pod networking.
This has practical consequences:
- A pod IP is a normal VPC address. Security groups, flow logs, route tables and VPC peering treat it like any other.
- Pod-to-pod traffic across nodes is routed by the VPC itself, with no encapsulation overhead.
- Anything in the VPC, such as an RDS instance or an on-premises host reached over Direct Connect, can reach a pod IP directly if routes and security groups allow it.
- Pods consume subnet addresses. A small subnet can run out of IPs long before the nodes run out of CPU.
The plugin runs as a DaemonSet named aws-node in kube-system, so one copy runs on every node. EKS also installs it as a managed add-on, which a later chapter covers.
How IPs Reach a Pod
An EC2 instance has one or more elastic network interfaces (ENIs). Each ENI can hold a limited number of private IPv4 addresses, and both limits depend on the instance type. The VPC CNI uses this capacity as follows:
- The
aws-nodepod on the node runs a local daemon calledipamd(IP address management daemon). ipamdattaches ENIs to the instance and assigns extra secondary private IPs to them. These addresses form a warm pool.- When the kubelet starts a pod, the CNI binary takes one IP from the pool. It creates a veth pair (a virtual cable between the pod's network namespace and the node) and adds a route for that IP.
- When the pod is deleted, the IP returns to the pool.
Keeping IPs ready in advance makes pod startup fast, because the EC2 API call has already happened.
The Maximum Pod Count
Because every pod needs its own ENI address, the instance type caps how many pods a node can run. For classic secondary-IP mode the formula is:
max pods = ENIs x (IPv4 addresses per ENI - 1) + 2The "- 1" is the ENI's own primary address. The "+ 2" covers pods that use the host network, such as aws-node and kube-proxy, which do not consume ENI IPs.
An m5.large supports 3 ENIs with 10 addresses each, so it can run 3 x 9 + 2 = 29 pods. That is low for a node with 2 vCPUs and 8 GiB of memory only if your pods are tiny, but it is a real ceiling for dense workloads. AWS publishes per-instance limits in the eni-max-pods.txt file of the amazon-eks-ami repository.
Inspecting the Plugin on a Running Cluster
These commands show the plugin, its version, and the pod IPs in practice:
kubectl -n kube-system get daemonset aws-node
kubectl -n kube-system describe daemonset aws-node | grep -i "image:"
kubectl get pods -A -o wideIn the -o wide output, pods that do not use the host network show IPs inside your VPC CIDR. Compare them with the node's address range to confirm there is no overlay. Pods such as aws-node and kube-proxy show the node's own IP because they use host networking.
Tuning the Warm Pool
ipamd reads its settings from environment variables on the aws-node DaemonSet. These are the ones you will use most:
| Variable | Effect |
|---|---|
| `WARM_ENI_TARGET` | Number of whole spare ENIs to keep attached. Default is 1. |
| `WARM_IP_TARGET` | Number of spare IPs to keep ready. Overrides `WARM_ENI_TARGET` when set. |
| `MINIMUM_IP_TARGET` | Minimum total IPs to hold on a node. Used together with `WARM_IP_TARGET`. |
| `ENABLE_PREFIX_DELEGATION` | Assign /28 prefixes instead of single IPs. |
| `WARM_PREFIX_TARGET` | Number of spare /28 prefixes to keep ready. |
The default keeps a whole spare ENI attached. On an m5.large that holds up to 9 unused addresses per node, which is wasteful in a crowded subnet. Setting WARM_IP_TARGET to a small number such as 5 reduces the waste. The cost is more EC2 API calls, which can hit rate limits during large scale-ups. In big clusters, set MINIMUM_IP_TARGET too, so bursts do not cause a stream of small allocations.
Prefix Delegation for Denser Nodes
Prefix delegation makes each ENI slot hold a /28 prefix, which is 16 addresses, instead of one address. A node can then run far more pods: AWS recommends a limit of 110 for most instances and 250 for large ones. Prefix delegation requires Nitro-based instance types.
Enable it on the DaemonSet:
kubectl -n kube-system set env daemonset/aws-node \
ENABLE_PREFIX_DELEGATION=true \
WARM_PREFIX_TARGET=1The setting only affects nodes that start afterward, so existing nodes need to be replaced. The kubelet's pod limit must also be raised. For eksctl managed node groups, set maxPodsPerNode:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
managedNodeGroups:
- name: ng-dense
instanceType: m5.large
desiredCapacity: 2
maxPodsPerNode: 110Prefix delegation has one gotcha. A /28 must be a contiguous block of 16 free addresses in the subnet. In a subnet already fragmented by single-IP allocations, the request can fail even though many individual IPs are free. Use dedicated subnets for prefix-mode nodes, or create a subnet CIDR reservation of type "prefix" to protect the space.
Running Out of Addresses
Subnet exhaustion is the most common EKS networking problem. A /24 subnet has 251 usable addresses, and nodes, load balancers and warm pools all draw from it. There are three standard remedies:
- Larger subnets. Plan pod subnets as /19 or bigger.
- Custom networking. Add a secondary CIDR to the VPC, for example from the
100.64.0.0/10range. Create oneENIConfigper Availability Zone, pointing at a subnet in that range. Then setAWS_VPC_K8S_CNI_CUSTOMNETWORK_CFG=trueandENI_CONFIG_LABEL_DEF=topology.kubernetes.io/zoneonaws-node. Pods then take addresses from the secondary range while nodes keep their primary IPs. One side effect is that the node's primary ENI no longer hosts pods, which reduces max pods slightly. - IPv6 clusters. Choose IPv6 when you create the cluster. Pods get IPv6 addresses and the address supply is effectively unlimited. You must confirm that every dependency you call supports IPv6.
Security Groups and Egress
By default every pod on a node shares the node's security groups. The VPC CNI can attach separate security groups to individual pods (security groups for pods, enabled with ENABLE_POD_ENI=true). A later chapter on hardening covers it.
For traffic leaving the VPC, the CNI source-NATs pod traffic to the node's primary IP by default. Because the VPC cannot route a pod IP back from the internet, this is what makes outbound traffic work. If you instead route egress through a NAT gateway or transit gateway and want pod IPs preserved, you can set AWS_VPC_K8S_CNI_EXTERNALSNAT=true. Only do that if something else performs the translation.
Common Errors
| Symptom | Likely cause |
|---|---|
| Pod stuck in `ContainerCreating` with `failed to assign an IP address to container` | Subnet out of free IPs, or the node's ENIs are at their limit. |
| Pod stuck in `Pending` with `Too many pods` | Node reached its max pod count for the instance type. |
| New nodes join but pods never get IPs | `aws-node` is crash-looping. Its IAM role lacks the CNI permissions, or the add-on is out of date. |
| Prefix delegation enabled but pod count is unchanged | Node launched before the setting, or `maxPodsPerNode` was not raised. |
| Allocation failures in a half-empty subnet | Fragmented subnet with no contiguous /28 available. |
When IP assignment fails, check ipamd on the node, in /var/log/aws-routed-eni/ipamd.log. You can also read the aws-node pod logs with kubectl -n kube-system logs <aws-node-pod>.
Exercise
An m5.xlarge supports 4 ENIs with 15 IPv4 addresses each. How many pods can one node run in secondary-IP mode, and why might a subnet run out of IPs before the cluster runs out of CPU?
Show answer
4 x (15 - 1) + 2 = 58 pods. Each pod takes one subnet address, and the warm pool holds spare addresses per node, so a node can consume far more subnet addresses than the pods it runs. In a small subnet, many nodes plus their warm pools can use all the free addresses even when CPU and memory are still available.
Exercise
You enabled ENABLEPREFIXDELEGATION on aws-node, but an existing node still caps at 29 pods. Name two things to check.
Show answer
First, whether the node started before the setting was applied. Prefix mode only applies to nodes that launch afterward, so replace the node. Second, whether the kubelet max pods value was raised, for example with maxPodsPerNode in the eksctl node group.