Skip to content

EKS cross az data transfer

1

I'm working with an Amazon EKS cluster deployed across multiple Availability Zones (AZs) within the same VPC. While I want to maintain high availability, I'd like to optimize for cost by reducing cross-AZ data transfer charges. Ideally, I want pods to preferentially communicate with other pods in the same AZ when possible.

Here's my current setup:

EKS cluster with worker nodes spread across 3 AZs (e.g., us-east-1a, us-east-1b, us-east-1c) Using the Amazon VPC CNI plugin Pods are scheduled across different private subnets, one or more per AZ Currently experiencing significant cross-AZ data transfer costs

Has anyone implemented service mesh or similar for cost optimization?

Any guidance or example configuration would be greatly appreciated!

Thanks in advance.

asked a year ago609 views

1 Answer
2
Accepted Answer

You can significantly reduce cross-AZ data transfer costs in EKS by implementing Traffic Distribution using Kubernetes Services. This approach keeps traffic within the same AZ when possible while maintaining high availability.

If you don't need to deploy Istio or other service mesh, just using Traffic Distribution with Kubernetes Services is the most effective approach, as documented in the Kubernetes Traffic Distribution documentation.

Implementation

Step 1: Enable Traffic Distribution on your Services

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 8080
  trafficDistribution: PreferClose

The PreferClose value ensures that traffic is routed to endpoints that are topologically close (same AZ) when possible, falling back to other endpoints when local ones are unavailable.

Step 2: Ensure your nodes have proper zone labels

# Verify nodes have zone labels (should be automatic with EKS)
kubectl get nodes --show-labels | grep topology.kubernetes.io/zone

Step 3: Configure your Deployments with zone awareness

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 6  # 2 per AZ for example
  template:
    spec:
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app: my-app

Advanced Architecture: Independent AZ Scaling

⚠️ Important Consideration: If you implement Traffic Distribution with PreferClose, you may want to scale each AZ independently to handle varying load patterns. This prevents overloading a single AZ when it receives more traffic from clients in that zone.

Recommended Architecture:

Single Service with Multiple Deployments and Individual HPAs

# Deployment for us-east-1a
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-us-east-1a
spec:
  template:
    spec:
      nodeSelector:
        topology.kubernetes.io/zone: us-east-1a
      containers:
      - name: app
        image: my-app:latest
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
---
# HPA for us-east-1a
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app-hpa-us-east-1a
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app-us-east-1a
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
---
# Service that covers all AZ deployments
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app  # All deployments should have this label
  ports:
  - port: 80
    targetPort: 8080
  trafficDistribution: PreferClose

Repeat similar Deployment and HPA configurations for us-east-1b and us-east-1c

Benefits of This Approach:

  • Cost Optimization: Reduces cross-AZ data transfer charges by keeping traffic local with PreferClose
  • Independent Scaling: Each AZ can scale based on its specific load patterns
  • High Availability: Maintains fault tolerance across AZs
  • Automatic Failover: Traffic automatically routes to other AZs if local pods are unavailable
AWS

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.