AWS VPC Networking Deep-Dive for DevOps: Subnets, Route Tables & NAT Gateways
· Sourabh G Kulkarni
Why private EKS pods fail to reach the internet, mastering public vs. private subnets, security groups vs. NACLs, and eliminating NAT Gateway cost traps.

Almost every DevOps engineer has deployed a private Kubernetes pod or EC2 instance only to discover it cannot pull container images or talk to external APIs. In 90% of cases, the root cause is not DNS or container permissions—it is an improperly wired Virtual Private Cloud (VPC).
Understanding the relationship between subnets, route tables, Internet Gateways (IGW), and NAT Gateways is fundamental to designing reliable, cost-effective cloud infrastructure.
flowchart TD
Internet((Public Internet))
IGW[Internet Gateway]
subgraph VPC["AWS VPC (10.0.0.0/16)"]
subgraph PublicSubnet["Public Subnet (10.0.1.0/24)"]
ALB["Application Load Balancer (Public IP)"]
NAT["NAT Gateway (Elastic IP)"]
end
subgraph PrivateSubnet["Private Subnet (10.0.10.0/24)"]
Pod["EKS Worker Node / App Pod (Private IP only)"]
DB["RDS PostgreSQL Database"]
end
end
Internet <-->|Direct Inbound/Outbound| IGW
IGW <--> ALB
IGW <--> NAT
Pod -->|Outbound traffic to APIs / Docker Hub| NAT
ALB -->|Forward traffic on Port 8080| Pod
Pod -->|Internal query on Port 5432| DB
Internet x-.-x|BLOCKED (No route)| PrivateSubnet
1. Public vs. Private Subnets: The Route Table Difference
In AWS, what makes a subnet "public" is not an intrinsic property of the subnet itself. It is defined strictly by its Route Table:
- Public Subnet: Its route table has an explicit route directing
0.0.0.0/0to an Internet Gateway (IGW) (igw-xxxxxx). - Private Subnet: Its route table directs
0.0.0.0/0to a NAT Gateway (nat-xxxxxx) located in a public subnet.
The Flow of Outbound Traffic:
- A private pod (
10.0.10.45) sends a request toapi.stripe.com. - The private route table routes
0.0.0.0/0to the NAT Gateway in the public subnet. - The NAT Gateway translates the private source IP to its public Elastic IP (EIP).
- The public route table forwards the packet out through the Internet Gateway to the internet.
- Inbound traffic initiated from the outside world directly to the private IP is physically impossible because the private subnet lacks an IGW route.
2. Security Groups vs. Network ACLs (NACLs)
Two layers of packet filtering protect your VPC:
| Feature | Security Group (SG) | Network ACL (NACL) |
|---|---|---|
| Operating Layer | Virtual Network Interface (ENI / Instance) | Subnet boundary |
| State Tracking | Stateful: If inbound traffic is allowed, outbound response is automatically allowed | Stateless: Inbound and outbound rules must be explicitly configured |
| Rule Evaluation | All rules evaluated together | Evaluated in numerical order (100, 200, 300) |
| Action Types | ALLOW rules only (implicit deny) | ALLOW and DENY rules |
Production Rule: Keep NACLs at default-allow, and use granular Security Groups to restrict traffic between tiers (e.g. Allow port 5432 ONLY from sg-api-backend).
3. The Multi-Thousand Dollar NAT Gateway Cost Trap
AWS charges ~$0.045 per hour per NAT Gateway, plus $0.045 per Gigabyte of data processed.
If your EKS pods in private subnets download large Docker images from Amazon ECR or transfer gigabytes of log files to Amazon S3 through a NAT Gateway, your monthly AWS bill can spike by thousands of dollars unnecessarily.
The Solution: VPC Endpoints (AWS PrivateLink)
Create VPC Gateway Endpoints for S3 and DynamoDB (which are 100% free!):
# Free S3 VPC Endpoint - Routes traffic to S3 directly over AWS internal network
resource "aws_vpc_endpoint" "s3" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.us-east-1.s3"
route_table_ids = [aws_route_table.private.id]
}
By adding a VPC endpoint, traffic between your private pods and S3 never leaves the AWS internal fabric and never touches the NAT Gateway, slashing egress data transfer costs to zero.