--- name: eks-networking description: EKS networking configuration including VPC CNI, load balancers, and network policies. Use when setting up cluster networking, configuring ingress/load balancing, implementing network security, troubleshooting connectivity, or optimizing network costs. --- # EKS Networking Comprehensive guide for configuring Amazon EKS networking including VPC CNI plugin, load balancers, network policies, and security. ## Overview EKS networking involves several key components working together: 1. **VPC CNI Plugin** - Assigns real VPC IP addresses to pods 2. **Load Balancers** - ALB for Layer 7, NLB for Layer 4 traffic 3. **Network Policies** - Control pod-to-pod and pod-to-external traffic 4. **Security Groups for Pods** - AWS-level network security 5. **DNS** - CoreDNS for in-cluster, ExternalDNS for external records 6. **Service Discovery** - AWS Cloud Map for multi-cluster ## Quick Start ### 1. Enable VPC CNI with Prefix Mode ```bash # Update VPC CNI addon with prefix delegation aws eks update-addon \ --cluster-name my-cluster \ --addon-name vpc-cni \ --addon-version v1.19.2-eksbuild.1 \ --configuration-values '{ "env": { "ENABLE_PREFIX_DELEGATION": "true", "WARM_PREFIX_TARGET": "1" } }' # Verify configuration kubectl get daemonset -n kube-system aws-node -o yaml | grep ENABLE_PREFIX_DELEGATION ``` ### 2. Install AWS Load Balancer Controller ```bash # Create IAM policy curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.11.0/docs/install/iam_policy.json aws iam create-policy \ --policy-name AWSLoadBalancerControllerIAMPolicy \ --policy-document file://iam_policy.json # Create IRSA eksctl create iamserviceaccount \ --cluster=my-cluster \ --namespace=kube-system \ --name=aws-load-balancer-controller \ --attach-policy-arn=arn:aws:iam::ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy \ --approve # Install via Helm helm repo add eks https://aws.github.io/eks-charts helm repo update helm install aws-load-balancer-controller eks/aws-load-balancer-controller \ -n kube-system \ --set clusterName=my-cluster \ --set serviceAccount.create=false \ --set serviceAccount.name=aws-load-balancer-controller ``` ### 3. Create ALB Ingress ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: app-ingress annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip alb.ingress.kubernetes.io/group.name: shared-alb alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]' alb.ingress.kubernetes.io/ssl-redirect: '443' alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:region:account:certificate/xxx spec: ingressClassName: alb rules: - host: app.example.com http: paths: - path: / pathType: Prefix backend: service: name: app-service port: number: 80 ``` ### 4. Enable Network Policies ```bash # VPC CNI v1.14+ supports network policies natively kubectl set env daemonset -n kube-system aws-node ENABLE_NETWORK_POLICY=true # Apply a network policy kubectl apply -f - < external-dns-policy.json < | grep IP # Check CNI logs kubectl logs -n kube-system -l k8s-app=aws-node --tail=50 # Verify ENI attachments aws ec2 describe-network-interfaces \ --filters "Name=attachment.instance-id,Values=i-xxx" ``` ### Verify Load Balancer Configuration ```bash # Check ingress status kubectl get ingress -A kubectl describe ingress # Check ALB controller logs kubectl logs -n kube-system deployment/aws-load-balancer-controller # Verify target groups aws elbv2 describe-target-groups aws elbv2 describe-target-health --target-group-arn ``` ### Test Network Policies ```bash # Create test pod kubectl run test-pod --image=nicolaka/netshoot -it --rm -- /bin/bash # Test connectivity curl http://service-name:port nc -zv service-name port # Verify policy applied kubectl get networkpolicy kubectl describe networkpolicy ``` ## Reference Documentation For detailed information, see: - **VPC CNI**: `references/vpc-cni.md` - CNI plugin configuration, modes, and optimization - **Load Balancers**: `references/load-balancers.md` - ALB, NLB, and AWS Load Balancer Controller - **Network Policies**: `references/network-policies.md` - Network policies, security groups, and segmentation ## Best Practices ### IP Address Management - Use prefix delegation mode for high pod density clusters - Consider IPv6 for new clusters to avoid IP exhaustion - Monitor IP usage with CNI metrics helper - Plan subnets with 2x expected IP requirements ### Load Balancing - Use IngressGroups to share ALBs and reduce costs - Set target-type to `ip` for best performance - Enable cross-zone load balancing for high availability - Use NLB for static IP requirements ### Network Security - Enable network policies (VPC CNI v1.14+ or Calico) - Combine NetworkPolicies with Security Groups for Pods (defense-in-depth) - Default deny, explicit allow policy approach - Use private subnets for worker nodes ### Performance and Cost - Deploy VPC endpoints for AWS services (reduces NAT costs) - Use topology-aware routing to minimize cross-AZ traffic - Enable prefix delegation to reduce ENI pressure - Monitor cross-AZ traffic with Container Network Observability ### High Availability - Spread subnets across at least 3 availability zones - Use multiple replicas for critical services - Configure pod topology spread constraints - Enable cross-zone load balancing ## Troubleshooting ### Pod Can't Get IP Address **Symptoms**: Pod stuck in ContainerCreating **Check**: ```bash # View CNI logs kubectl logs -n kube-system -l k8s-app=aws-node # Check available IPs kubectl get nodes -o jsonpath='{.items[*].status.allocatable.pods}' # Verify ENI limits not reached aws ec2 describe-instances --instance-ids i-xxx ``` **Solutions**: - Enable prefix delegation mode - Use larger instance types (more ENIs) - Add more nodes to cluster ### Ingress Not Creating ALB **Symptoms**: No load balancer provisioned for Ingress **Check**: ```bash # Verify controller running kubectl get pods -n kube-system | grep aws-load-balancer-controller # Check controller logs kubectl logs -n kube-system deployment/aws-load-balancer-controller # Verify subnet tags aws ec2 describe-subnets --subnet-ids subnet-xxx ``` **Solutions**: - Ensure subnets properly tagged - Verify IAM permissions for controller - Check IngressClass specified correctly ### Network Policy Not Working **Symptoms**: Traffic not blocked as expected **Check**: ```bash # Verify network policy enabled kubectl get daemonset -n kube-system aws-node -o yaml | grep ENABLE_NETWORK_POLICY # Check policy applied kubectl get networkpolicy -A kubectl describe networkpolicy ``` **Solutions**: - Enable network policy support in CNI - Verify label selectors match pods - Check policy has both ingress and egress rules ### DNS Resolution Failures **Symptoms**: Pods can't resolve service names **Check**: ```bash # Test DNS from pod kubectl run -it --rm debug --image=busybox --restart=Never -- nslookup kubernetes.default # Check CoreDNS status kubectl get pods -n kube-system -l k8s-app=kube-dns # View CoreDNS logs kubectl logs -n kube-system -l k8s-app=kube-dns ``` **Solutions**: - Scale CoreDNS replicas - Check CoreDNS ConfigMap - Verify network policy allows DNS traffic ## 2025 Recommendations ### CNI Selection - **Default**: VPC CNI with prefix delegation mode - **IPv4 exhaustion**: IPv6 clusters (AWS recommended) - **Advanced policies**: VPC CNI + Calico policy-only agent - **Maximum features**: Cilium (for EKS Hybrid Nodes or advanced use cases) ### Load Balancing - **AWS Native**: AWS Load Balancer Controller (recommended) - **Multi-cloud portability**: NGINX Ingress with NLB - **Service mesh**: Istio Gateway (App Mesh deprecated Sept 2026) ### Network Security - VPC CNI native network policies (v1.14+) for most use cases - Calico for enhanced policy features and observability - Cilium for eBPF-powered security and deep insights - Always combine with Security Groups for Pods (defense-in-depth) ### Cost Optimization - VPC endpoints for all AWS services (ECR, S3, CloudWatch, etc.) - Topology-aware routing to minimize cross-AZ traffic - Single NAT Gateway per AZ (not per subnet) - Monitor network costs with Container Network Observability