Anatomy of a Production AWS VPC Module: Three-Tier Subnets, NACLs, Flow Logs, and Kubernetes-Ready Tags

A VPC looks simple until you deploy a real one: multi-AZ subnet tiers, routing, defense-in-depth NACLs, flow logging, and the tags EKS needs to discover subnets for load balancers. This post dissects a production VPC module that handles all of it.

The three-tier subnet layout

The module carves the VPC CIDR into three tiers, spread across every AZ:

Tier Purpose Internet route
public load balancers, NAT gateways via IGW
private-app compute: EKS nodes, ECS, EC2 via NAT gateway
private-persistence data: RDS, ElastiCache no internet route at all

The persistence tier having no NAT route is the detail that matters: databases cannot initiate outbound internet connections, which removes an entire class of exfiltration and update-hijack risk. Each tier gets its own route tables — one public table shared across AZs, but one private route table per AZ, because each AZ’s NAT gateway is a single point of failure and cross-AZ NAT routing would couple zone fates.

Defense in depth: NACLs done programmatically

Security groups are stateful; NACLs are the stateless second layer. Rather than hand-writing NACL rules, the module computes them from helper modules (network-acl-inbound, network-acl-outbound, port-range-calculator) that translate a list of allowed port ranges into correctly-numbered ACL entries — ephemeral ports included, which is the part everyone forgets and then wonders why return traffic dies.

Flow logs are not optional

Every VPC gets flow logs to CloudWatch from day one. Retrofitting them after an incident means the incident happened while you were blind. Cost is trivial next to the debugging time they save — they’re how you answer “was it the NACL, the SG, or the route?” in minutes instead of hours.

The Kubernetes tag contract

This is the subtlest part. EKS discovers subnets for load balancers by tag, not by configuration:

# public subnets — where internet-facing ELBs land
"kubernetes.io/role/elb" = "1"

# private-app subnets — where internal ELBs land
"kubernetes.io/role/internal-elb" = "1"

# all subnets — cluster ownership
"kubernetes.io/cluster/<cluster-name>" = "shared"

Get these wrong and the classic symptom appears: service type=LoadBalancer hangs forever with no error telling you why, because the controller couldn’t find any eligible subnet. Baking the tags into the VPC module means the cluster team can’t misconfigure them.

Optional add-ons

The module also wires optional VPC peering and a DNS forwarder (Route 53 Resolver endpoints) so a management VPC and app VPCs can resolve each other’s private zones — the bridge to centralized DNS, covered in the Route 53 post.

Takeaway

A production VPC module earns its complexity: per-AZ route tables, computed NACLs, flow logs, persistence-tier isolation, and the EKS tag contract. Write it once, stamp it out per environment, and networking stops being the thing every incident starts with.


<
Previous Post
Aws Account Baseline Root
>
Next Post
Private Dns Across Multiple Vpcs