Goal
Enforce Kubernetes NetworkPolicy on EKS using the VPC CNI's built-in eBPF agent, then move namespaces to default-deny. The enforcement itself is easy to switch on. What breaks clusters is the traffic nobody wrote down: DNS, credential endpoints, the API server and admission webhooks.
Work through the checklist in order. Each section ends with a command that proves the step.
1. Prerequisites
- VPC CNI add-on recent enough to include the network policy agent. Check the EKS docs for the minimum version and stay on a current release; policy fixes land often.
- Linux EC2 nodes with a kernel that supports the agent's eBPF programs (current Amazon Linux 2023 and Bottlerocket AMIs do). Fargate pods are not enforced by this agent. For Windows and hybrid nodes, check the current documentation.
- You know which pods use
hostNetwork: true. Policies don't apply to them. - No other policy engine (Calico, Cilium) is enforcing on the same nodes. Two enforcers make debugging close to impossible.
CLUSTER=prod-eu1
aws eks describe-addon --cluster-name $CLUSTER --addon-name vpc-cni \
--query "addon.{Version:addonVersion,Config:configurationValues}"
kubectl get nodes -o custom-columns=NAME:.metadata.name,KERNEL:.status.nodeInfo.kernelVersion,OS:.status.nodeInfo.osImage
2. Enable enforcement
Enabling adds the aws-network-policy-agent container to the aws-node DaemonSet, and EKS runs the policy controller in the control plane. Nothing is blocked until you create a policy.
aws eks update-addon --cluster-name $CLUSTER --addon-name vpc-cni \
--resolve-conflicts PRESERVE \
--configuration-values '{"enableNetworkPolicy":"true","nodeAgent":{"enablePolicyEventLogs":"true","enableCloudWatchLogs":"true"}}'
Policy event logs record every allow and deny decision. They are invaluable during rollout but add CPU on the node and CloudWatch Logs cost, and the cloud logs option needs the node role (or the aws-node identity) to have CloudWatch Logs permissions. Turn decision logs off once the rollout is stable.
Verify:
kubectl -n kube-system get ds aws-node \
-o jsonpath='{range .spec.template.spec.containers[*]}{.name}{"\n"}{end}'
kubectl get crd policyendpoints.networking.k8s.aws
You should see aws-node and aws-network-policy-agent, and the PolicyEndpoint CRD.
3. Decide on the enforcing mode
| Mode | New pod behaviour | Use when |
|---|---|---|
| Standard (default) | Pod starts with traffic allowed. The policy applies once the agent has reconciled it, usually within seconds | Most clusters, gradual rollout |
| Strict | Pod starts with traffic denied until policies are reconciled | Regulated workloads where even a few seconds of open egress matters |
Strict mode is set with the NETWORK_POLICY_ENFORCING_MODE environment variable on aws-node. Read the current documentation for exactly how it treats pods that have no matching policy, and test it in a non-production cluster first. It can delay readiness for pods whose startup makes network calls.
4. Allow the traffic everyone forgets
Write these as a baseline per namespace before any default-deny. Labels and namespace names vary; check yours.
| Traffic | Direction | Destination / source | Why it breaks |
|---|---|---|---|
| DNS | Egress | CoreDNS pods in kube-system, UDP and TCP 53 | Every name lookup fails, which looks like "everything is down" |
| EKS Pod Identity | Egress | 169.254.170.23/32 TCP 80 (IPv6: fd00:ec2::23) | SDK can't get credentials, NoCredentialProviders |
| IRSA | Egress | STS endpoint on 443 (VPC endpoint subnet CIDRs or public) | AssumeRoleWithWebIdentity times out |
| Kubernetes API | Egress | Cluster endpoint ENIs on 443 (control plane subnet CIDRs) | Operators, controllers and leader election fail |
| Admission webhooks | Ingress | Control plane subnets to the webhook port | API server can't call the webhook; creates are rejected or time out |
| Health checks from load balancers | Ingress | ALB/NLB subnets (IP targets) to the container port | Targets go unhealthy |
| AWS service endpoints | Egress | Interface endpoint subnet CIDRs or 0.0.0.0/0 on 443 | S3, SQS, Secrets Manager calls hang |
A baseline for a namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: baseline-egress
namespace: payments
spec:
podSelector: {}
policyTypes: [Egress]
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- { protocol: UDP, port: 53 }
- { protocol: TCP, port: 53 }
- to:
- ipBlock: { cidr: 169.254.170.23/32 }
ports:
- { protocol: TCP, port: 80 }
- to:
- ipBlock: { cidr: 10.20.0.0/22 } # control plane and endpoint subnets
ports:
- { protocol: TCP, port: 443 }
Warning
NetworkPolicymatches pod IPs, not Service ClusterIPs. AnipBlockcontaining the Service CIDR won't allow traffic to a Service. Select the backend pods withpodSelector/namespaceSelectorinstead.
The EKS cluster endpoint ENIs move when the control plane scales or is upgraded. Allow the subnets you gave the cluster, not individual IPs.
5. Roll out default-deny one namespace at a time
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: payments
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
Order of operations for each namespace:
- Baseline egress policy applied (section 4).
- Application allow policies applied: who may call this service, and what this service calls.
- Decision logs watched for denies for at least one full business cycle (batch jobs, month-end).
- Default-deny applied last.
- Rollback is a single
kubectl delete networkpolicy default-deny -n payments.
Start with stateless services that have good health checks. Leave kube-system, ingress controllers and service-mesh control planes until the end.
Caution
A default-deny in a namespace that runs an admission webhook can stop pod creation cluster-wide if the webhook's
failurePolicyisFail. Confirm the webhook ingress rule works before applying default-deny there.
6. Debug a drop
Find which node the pod is on, then check what the agent sees.
POD=checkout-7d9c8b6f4-x2k9q; NS=payments
kubectl get pod $POD -n $NS -o wide
kubectl get policyendpoints -n $NS
kubectl describe policyendpoints -n $NS <name>
PolicyEndpoint objects are the controller's resolved form of your policies: the actual pod IPs and CIDRs allowed. If the peer pod's IP is missing, the problem is selectors or labels, not the node.
On the node (through SSM Session Manager):
sudo tail -f /var/log/aws-routed-eni/network-policy-agent.log
sudo grep -i deny /var/log/aws-routed-eni/network-policy-agent.log | tail -20
# Inspect loaded eBPF programs and maps (subcommands vary by version; run --help)
sudo /opt/cni/bin/aws-eks-na-cli ebpf progs
sudo /opt/cni/bin/aws-eks-na-cli ebpf loaded-ebpfdata
The agent also exposes Prometheus metrics on port 61680 if you want to scrape it.
| Symptom | Likely cause | Check |
|---|---|---|
| Policies have no effect | Enforcement not enabled, or pod is hostNetwork | Section 2 verify; pod spec |
| DNS timeouts after default-deny | No egress to CoreDNS on UDP and TCP 53 | Baseline policy |
NoCredentialProviders or STS timeouts | Pod Identity or STS egress missing | Section 4 table |
Webhook timeouts on kubectl apply | Ingress from control plane subnets missing | Webhook namespace policies |
Peer IP missing in PolicyEndpoint | Selector or namespace label mismatch | kubectl get pods --show-labels |
| Brief traffic before policy applies | Standard mode behaviour | Consider strict mode |
7. Operate it
- Policies live in Git with the application manifests and go through review.
- A CI check rejects namespaces without a baseline policy once rollout completes.
- VPC CNI upgrades are tested in a lower environment with policies applied, because the agent ships with the add-on.
- Decision logs are switched off, or sent to a short retention log group, after rollout.
- The on-call runbook includes the "delete default-deny" rollback and the node log path.
Prevent it next time
Write the baseline policy into your namespace template so every new namespace gets DNS, credentials and API access from day one. Then default-deny becomes a one-line change rather than a migration.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get