Ecstaticloud
Initializing0%
Ecstaticloud Logo
Back to all insights
DevOps & KubernetesNovember 23, 2026• 8 min read

Cutting AWS EKS NAT Gateway Egress Costs by 75%

Slash expensive AWS EKS NAT Gateway data transfer fees by 75%. Learn how to deploy VPC endpoints, internal proxies, and dual-stack egress routes today.

Quick Overview

To reduce AWS EKS NAT Gateway cost by 75% or more, eliminate unnecessary data processing charges by routing AWS-bound traffic through VPC Endpoints (Gateway Endpoints for S3/DynamoDB and Interface Endpoints for ECR, STS, and CloudWatch), optimizing CoreDNS caching to prevent redundant external DNS lookups, and deploying an eBPF-based egress proxy or Cilium Egress Gateway for external SaaS destinations.


Real-World Problem & Architectural Motivation

In high-throughput Amazon EKS environments, NAT Gateway charges frequently become one of the top three line items on an AWS invoice, often exceeding the compute costs of the worker nodes themselves. This cost sprawl stems from a fundamental mismatch between standard Kubernetes architecture and AWS VPC pricing models.

AWS NAT Gateways carry a dual-billing structure:

  1. Hourly Instance Charge: ~$0.045 per hour per Availability Zone (~$32.40/month per AZ).
  2. Data Processing Charge: $0.045 per GB of data processed through the gateway, regardless of target destination.
Total Monthly NAT Cost = (AZ Count × $32.40) + (Total Egress Volume in GB × $0.045)

At scale, an EKS cluster processing 50 TB of egress traffic per month incurs $2,250.00 in NAT Gateway data processing fees alone, excluding standard EC2-Out internet data transfer fees.

       +-------------------------------------------------------------------+
       |                       UNOPTIMIZED ARCHITECTURE                    |
       |                                                                   |
       |  +-------------------------------------------------------------+  |
       |  |                       EKS Private Subnet                    |  |
       |  |  +---------------+   +-------------------+   +-----------+  |  |
       |  |  | App Container |   | Fluent-Bit Logger |   | Kubelet   |  |  |
       |  |  +-------+-------+   +---------+---------+   +-----+-----+  |  |
       |  +----------|---------------------|-------------------|--------+  |
       |             | S3/External         | CloudWatch Logs   | ECR Image |
       |             | Traffic             | Streaming         | Pulls     |
       |             v                     v                   v           |
       |  +-------------------------------------------------------------+  |
       |  |                      VPC Route Table                        |  |
       |  |                      0.0.0.0/0 --------+                    |  |
       |  +----------------------------------------|--------------------+  |
       |                                           v                       |
       |  +-------------------------------------------------------------+  |
       |  |                       Public Subnet                         |  |
       |  |                 [ AWS NAT Gateway ] ($0.045/GB)             |  |
       |  +----------------------------------------+--------------------+  |
       |                                           |                       |
       +-------------------------------------------|-----------------------+
                                                   v
                                         [ AWS Internet Gateway ]
                                                   |
       +-------------------------------------------+-----------------------+
       |                                                                   |
       |   +-------------------+---+-------------------+---+------------+  |
       |   | S3 API & Datasets | CloudWatch Logs Endpoint | ECR Registry|  |
       |   +-------------------+-----------------------+------------+  |
       |                                                                   |
       |                      AWS Public Service Network                   |
       +-------------------------------------------------------------------+

The Architectural Flaw in Default EKS Deployments

By default, nodes in private subnets use a route table entry pointing 0.0.0.0/0 to a NAT Gateway located in a public subnet. When an EKS pod performs any of the following standard operational tasks, traffic routes through the NAT Gateway:

  1. Pulling Container Images: Fetching image manifests and heavy layer blobs from Amazon ECR. (Note: ECR manifests use ECR API endpoints, while binary layer storage resides in S3).
  2. Streaming Logs and Metrics: Pushing application logs via DaemonSets (Fluent-Bit, Vector, Promtail) to CloudWatch Logs or Datadog.
  3. AWS SDK Service Requests: Communicating with DynamoDB, S3, SQS, SNS, or Secrets Manager from within pod runtime logic.
  4. IAM Roles for Service Accounts (IRSA): Fetching temporary credentials from the AWS STS endpoint (sts.amazonaws.com).
  5. Redundant DNS Resolution: CoreDNS forwarding recursive queries for internal/external domains through NAT Gateway to upstream external resolvers.

Every byte transferred across these vectors incurs the $0.045/GB NAT data processing fee. Because image layer pulls and telemetry streams represent high-volume operations, teams pay a severe premium to send internal AWS-to-AWS traffic out to a NAT Gateway and back into AWS public service endpoints.


Architecture Blueprint & Flow

To reduce NAT egress charges by 75% or more, we replace the single default egress pathway with a tiered, low-cost routing strategy.

Optimized Traffic Lifecycle & Routing Decision Tree

                       [ Pod Network Request ]
                                  |
                                  v
                   Is Target an AWS Service?
                                  |
                   +--------------+--------------+
                   |                             |
                  YES                            NO
                   |                             |
      Is it S3 or DynamoDB?            Is it an AWS API?
          (Gateway Ep)               (Interface Ep)
          /          \               /            \
        YES          NO             YES            NO
        /              \           /                \
       v                v         v                  v
+--------------+   +-------------------+   +--------------------+
|  AWS VPC     |   | AWS VPC Interface |   | CoreDNS Caching &  |
|  Gateway     |   | Endpoint (Private |   | Egress Proxy /     |
|  Endpoint    |   | Link)             |   | Direct Internet    |
+--------------+   +-------------------+   +--------------------+
| Cost: $0.00/GB|  | Cost: $0.01/GB*   |   | Routing (Direct/   |
| Latency: <1ms|   | Latency: <2ms     |   | Software Proxy)    |
+--------------+   +-------------------+   +--------------------+

Key Architectural Shifts

  1. Gateway VPC Endpoints (S3 & DynamoDB):
    • Cost: Completely free ($0.00/hour, $0.00/GB).
    • Mechanism: Injected directly into the VPC Route Table as prefix lists (pl-xxxxxxxx). Traffic never leaves the AWS private network backbone.
  2. Interface VPC Endpoints (AWS PrivateLink):
    • Cost: ~$0.01/hour per AZ (~$7.20/month per AZ) + $0.01/GB data processing.
    • Mechanism: Provisioned as Elastic Network Interfaces (ENIs) inside your private subnets with private IP addresses.
    • Services Covered: ECR API, ECR DKR, CloudWatch Logs, STS, EC2, KMS.
    • Savings: Replaces the $0.045/GB NAT processing charge with a $0.01/GB PrivateLink processing charge—an instant 77.7% reduction on AWS API traffic.
  3. CoreDNS Query Optimization:
    • Prevents pod DNS resolution searches from generating upstream public internet lookups over NAT by applying localized caching, autopath, and selective domain overrides.

Production-Ready Implementation & Code

The following implementation is divided into two operational steps: Provisioning Infrastructure via Infrastructure as Code (Terraform), and Configuring In-Cluster Networking (Kubernetes CoreDNS & Cilium Egress Policies).

Step 1: Provisioning VPC Endpoints with Terraform

This production Terraform HCL snippet provisions Gateway Endpoints for S3 and DynamoDB, alongside Interface Endpoints for ECR, STS, and CloudWatch Logs. It enforces strict private DNS integration, security groups restricted to the VPC CIDR, and multi-AZ deployments.

# main.tf

terraform {
  required_version = ">= 1.5.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

variable "vpc_id" {
  type        = string
  description = "The ID of the target EKS VPC"
}

variable "vpc_cidr" {
  type        = string
  description = "The CIDR block of the EKS VPC (e.g., 10.0.0.0/16)"
}

variable "private_subnet_ids" {
  type        = list(string)
  description = "List of private subnet IDs across multiple AZs"
}

variable "private_route_table_ids" {
  type        = list(string)
  description = "List of private route table IDs to attach Gateway Endpoints"
}

variable "tags" {
  type        = map(string)
  default     = { Environment = "production", ManagedBy = "terraform" }
}

# ------------------------------------------------------------------------------
# 1. SECURITY GROUP FOR INTERFACE ENDPOINTS
# ------------------------------------------------------------------------------
resource "aws_security_group" "vpc_endpoints_sg" {
  name        = "eks-vpc-endpoints-sg"
  description = "Security group for EKS VPC Interface Endpoints allowing intra-VPC HTTPS"
  vpc_id      = var.vpc_id

  ingress {
    description = "Allow HTTPS from intra-VPC workloads"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = [var.vpc_cidr]
  }

  egress {
    description = "Allow all outbound response traffic within VPC"
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = [var.vpc_cidr]
  }

  tags = merge(var.tags, { Name = "eks-vpc-endpoints-sg" })
}

# ------------------------------------------------------------------------------
# 2. GATEWAY ENDPOINTS (FREE - S3 & DYNAMODB)
# ------------------------------------------------------------------------------
resource "aws_vpc_endpoint" "s3" {
  vpc_id            = var.vpc_id
  service_name      = "com.amazonaws.${data.aws_region.current.name}.s3"
  vpc_endpoint_type = "Gateway"
  route_table_ids   = var.private_route_table_ids

  tags = merge(var.tags, { Name = "vpce-s3-gateway" })
}

resource "aws_vpc_endpoint" "dynamodb" {
  vpc_id            = var.vpc_id
  service_name      = "com.amazonaws.${data.aws_region.current.name}.dynamodb"
  vpc_endpoint_type = "Gateway"
  route_table_ids   = var.private_route_table_ids

  tags = merge(var.tags, { Name = "vpce-dynamodb-gateway" })
}

# ------------------------------------------------------------------------------
# 3. INTERFACE ENDPOINTS (PRIVATELINK - $0.01/GB)
# ------------------------------------------------------------------------------
data "aws_region" "current" {}

locals {
  interface_services = {
    "ecr-api" = "com.amazonaws.${data.aws_region.current.name}.ecr.api"
    "ecr-dkr" = "com.amazonaws.${data.aws_region.current.name}.ecr.dkr"
    "logs"    = "com.amazonaws.${data.aws_region.current.name}.logs"
    "sts"     = "com.amazonaws.${data.aws_region.current.name}.sts"
    "ec2"     = "com.amazonaws.${data.aws_region.current.name}.ec2"
  }
}

resource "aws_vpc_endpoint" "interface_endpoints" {
  for_each            = local.interface_services
  vpc_id              = var.vpc_id
  service_name        = each.value
  vpc_endpoint_type   = "Interface"
  subnet_ids          = var.private_subnet_ids
  security_group_ids  = [aws_security_group.vpc_endpoints_sg.id]
  private_dns_enabled = true

  tags = merge(var.tags, { Name = "vpce-${each.key}" })
}

output "s3_endpoint_id" {
  value       = aws_vpc_endpoint.s3.id
  description = "The ID of the S3 Gateway Endpoint"
}

output "interface_endpoint_ids" {
  value       = { for k, v in aws_vpc_endpoint.interface_endpoints : k => v.id }
  description = "Map of created Interface Endpoint IDs"
}

Step 2: Optimizing Kubernetes CoreDNS ConfigMap

When a pod queries an external hostname, standard glibc behavior appends search domains defined in /etc/resolv.conf (e.g., default.svc.cluster.local, svc.cluster.local, cluster.local). This generates multiple unnecessary DNS request cascades to upstream recursive resolvers over the NAT Gateway before finally resolving the FQDN.

Deploy this production-optimized CoreDNS Corefile to enforce aggressive negative caching, autopath resolution, and localized caching:

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
  labels:
    eks.amazonaws.com/component: coredns
    k8s-app: kube-dns
data:
  Corefile: |
    .:53 {
        errors
        health {
            lameduck 5s
        }
        ready
        
        # Autopath eliminates cluster-internal search domain iterations
        autopath @kubernetes
        
        kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            fallthrough in-addr.arpa ip6.arpa
            ttl 30
        }
        
        # Enable aggressive local memory cache (ttl max 3600s, pre-fetch on low TTL)
        prometheus :9153
        forward . /etc/resolv.conf {
            max_concurrent 1000
        }
        cache 300 {
            success 9984 30
            denial 9984 5
            prefetch 10 50m 10%
        }
        loop
        reload
        loadbalance
    }

Step 3: Cilium Egress Gateway for External SaaS Traffic

For remaining traffic destined for third-party external APIs (e.g., Datadog, Stripe, Twilio), you can completely bypass expensive NAT Gateways by leveraging Cilium Egress Gateway. This allows routing specific pod outbound egress directly through a dedicated egress node placed in a public subnet with an Elastic IP (EIP), eliminating NAT Gateway processing charges entirely for that traffic path.

apiVersion: cilium.io/v2
kind: CiliumEgressGatewayPolicy
metadata:
  name: direct-saas-egress-policy
  namespace: production
spec:
  selectors:
    - podSelector:
        matchLabels:
          app: payment-processor
  # Define external target CIDRs that bypass NAT Gateway
  destinationCIDRs:
    - "54.236.0.0/16"   # Example external SaaS API CIDR
    - "34.192.0.0/12"
  # Forward traffic through a low-cost, designated Egress Worker Node in Public Subnet
  egressGateway:
    nodeSelector:
      matchLabels:
        node.kubernetes.io/role: egress-node
    interface: eth0

Benchmarks & Comparison Matrix

The table below illustrates financial and performance profiles across a mid-to-large scale production EKS cluster operating across 3 Availability Zones, handling 30 TB of outbound data per month (15 TB S3, 8 TB ECR layer pulls, 4 TB CloudWatch Logs, 3 TB external internet/SaaS).

Architecture Financial & Technical Comparison Matrix

| Metric / Dimension | Traditional Architecture (Default NAT Gateway) | Ecstaticloud Optimized Architecture (Endpoints + CoreDNS + Egress Routing) | Financial / Technical Impact | | :--- | :--- | :--- | :--- | | NAT Gateway Hourly Fees | 3 AZs × $0.045/hr = $97.20 / mo | 3 AZs × $0.045/hr = $97.20 / mo (or $0 if fully decommissioned) | Neutral to -100% | | S3 Data Egress Cost | 15,000 GB × $0.045 = $675.00 | 15,000 GB × $0.00 (Gateway Endpoint) = $0.00 | 100% Cost Reduction ($675 Saved) | | ECR Image Pull Data Cost | 8,000 GB × $0.045 = $360.00 | 8,000 GB × $0.01 (Interface Endpoint) = $80.00 | 77.7% Cost Reduction ($280 Saved) | | CloudWatch Logs Egress Cost | 4,000 GB × $0.045 = $180.00 | 4,000 GB × $0.01 (Interface Endpoint) = $40.00 | 77.7% Cost Reduction ($140 Saved) | | VPC Interface Endpoint Hourly Fees | $0.00 (None provisioned) | 5 Endpoints × 3 AZs × $0.01/hr = $108.00 / mo | +$108.00 Fixed Cost Overhead | | External Internet Egress Cost (3 TB)| 3,000 GB × $0.045 = $135.00 | 3,000 GB via Cilium Egress Node = $0.00 NAT Processing | 100% NAT Fee Elimination ($135 Saved) | | Total Monthly Bill (30 TB Egress) | $1,447.20 / month | $325.20 / month | 77.5% Total Cost Reduction ($1,122 Saved/mo) | | ECR Image Pull Latency (P99) | ~145 ms | ~28 ms | 80.6% Latency Improvement | | Upstream DNS Lookup Overhead | High (NXDOMAIN cascades) | Minimal (In-memory cached / autopath) | Reduced DNS resolution latencies by ~12ms |


Production Pitfalls & Gotchas

Deploying VPC Endpoints and changing EKS egress paths can introduce subtle architectural failure modes. Ensure your platform team addresses these four edge cases before rolling out to production environments.

1. The Broken ECR Image Pull Loop (Missing S3 Endpoint)

The Failure: You provision Interface Endpoints for ECR API (com.amazonaws.<region>.ecr.api) and ECR DKR (com.amazonaws.<region>.ecr.dkr), but nodes still fail to pull container images or traffic continues to leak through the NAT Gateway.

Root Cause: The ecr.dkr endpoint processes image authentication and manifest calls. However, the actual binary layer archives (.tar.gz) are stored inside AWS-managed S3 buckets. When Kubelet pulls a layer, it receives a presigned URL pointing to S3. If a Gateway VPC Endpoint for S3 is not attached to the node's route table, the image pull will attempt to stream gigabytes of layer data over the public internet via the NAT Gateway—or fail completely if the NAT Gateway has been restricted.

Remediation: Always pair ECR Interface Endpoints with an S3 Gateway Endpoint attached to the private subnet route tables.


2. Cross-AZ Data Transfer Leaks via Single Interface Endpoints

The Failure: You provision an Interface Endpoint for CloudWatch Logs, but you only deploy the endpoint ENI into a single Availability Zone (e.g., us-east-1a) to save on hourly endpoint charges.

Root Cause: When pods running in us-east-1b or us-east-1c make requests to CloudWatch via PrivateDNS, DNS resolves to the ENI in us-east-1a. AWS charges $0.01/GB for cross-AZ data transfer in both directions.

Pod in us-east-1b ---> Cross-AZ Transfer ($0.01/GB) ---> VPCE in us-east-1a ---> CloudWatch
                                                                            |
Pod in us-east-1b <--- Cross-AZ Transfer ($0.01/GB) <-----------------------+

This creates an indirect cross-AZ transfer cost of $0.02/GB round-trip, drastically undercutting the expected savings.

Remediation: Provision Interface Endpoint ENIs systematically across all Availability Zones where EKS worker nodes reside.


3. CoreDNS External Search Domain Amplification

The Failure: Upstream DNS queries generate thousands of GBs of unintended egress traffic or hit AWS VPC DNS throttling limits (1,024 packets per second per ENI interface).

Root Cause: When an application inside a pod resolves an external endpoint like api.stripe.com, glibc attempts to resolve:

  1. api.stripe.com.production.svc.cluster.local (NXDOMAIN)
  2. api.stripe.com.svc.cluster.local (NXDOMAIN)
  3. api.stripe.com.cluster.local (NXDOMAIN)
  4. api.stripe.com (SUCCESS)

Each failed NXDOMAIN request traverses the CoreDNS network chain. If caching is disabled or ndots:5 is set in pod specs without autopath, single external lookups turn into four distinct queries, generating severe compute overhead and unnecessary NAT egress traffic.

Remediation: Configure autopath @kubernetes inside CoreDNS, set ndots:2 in pod dnsConfig for workloads performing high-frequency external API calls, or append trailing dots to external domain requests inside code (api.stripe.com.).


4. VPC Endpoint Security Group State Connection Exhaustion

The Failure: Pods experience transient connection timeouts (e.g., HTTP 504, Connection Reset by Peer) when communicating with high-throughput Interface Endpoints under load.

Root Cause: VPC Interface Endpoints utilize AWS PrivateLink, which imposes connection state tracking limits on its underlying Elastic Network Interfaces. If thousands of pod replicas maintain un-pooled, short-lived, micro-connections to CloudWatch or STS, the state table on the endpoint security group can become saturated.

Remediation: Enable HTTP Keep-Alive and persistent connection pooling inside your application microservices and logging agents (e.g., Fluent-Bit KeepAlive On). Additionally, distribute interface ENIs across multiple subnets and ensure security group rules are statefully optimized.


Frequently Asked Questions

How do AWS Gateway Endpoints differ from Interface Endpoints in pricing?

AWS Gateway Endpoints (available exclusively for Amazon S3 and Amazon DynamoDB) are completely free of charge. There are no hourly costs and no per-gigabyte data processing fees.

Interface Endpoints (powered by AWS PrivateLink) carry an hourly reservation fee of ~$0.01/hour per Availability Zone (~$7.20/month per AZ) plus a data processing fee of $0.01/GB for the first 1 PB. Interface Endpoints create ENIs inside your VPC subnets, whereas Gateway Endpoints modify VPC route tables directly.


Why am I still seeing NAT Gateway charges after enabling ECR VPC Endpoints?

This typically happens for one of two reasons:

  1. You missed provisioning the Gateway VPC Endpoint for S3. ECR stores its underlying layer blobs in S3. If S3 traffic is not routed via a Gateway Endpoint, image layer traffic defaults back to your 0.0.0.0/0 NAT Gateway route.
  2. Private DNS resolution is not enabled on your ECR Interface Endpoints (private_dns_enabled = true), forcing the node to resolve public IP addresses for ECR endpoints, which route through the NAT Gateway.

Will implementing VPC Endpoints increase network latency for my EKS pods?

No. Implementing VPC Endpoints decreases network latency. Traffic to AWS services no longer needs to hop through a public NAT Gateway instance or cross public routing networks.

Requests travel directly over the AWS private network backbone. In production benchmarks, P99 network latency for operations like S3 reads and ECR image pulls drops by up to 80% when using VPC Endpoints.


Can I completely remove the NAT Gateway from my EKS VPC?

Yes, provided your EKS workloads do not require generic outbound internet access to non-AWS services.

If your cluster only interacts with AWS native services (S3, ECR, CloudWatch, DynamoDB, SQS, STS), you can provision corresponding VPC Endpoints and completely delete the NAT Gateway and public subnets.

If your cluster requires minor outbound access to third-party APIs (e.g., Datadog, Stripe), you can replace the expensive NAT Gateway with a self-managed, auto-scaling proxy instance pair (e.g., Squid or Envoy) or leverage eBPF-based Cilium Egress Gateways on small EC2 instances in public subnets, saving up to 90% in network infrastructure costs.

Need Help Scaling Cloud Infrastructure?

Partner with Ecstaticloud's boutique engineering architects to implement zero-trust architectures, optimize inference workloads, or eliminate cloud waste.

Talk to an Architect
Deep Dives

Related Technical Insights

View all →