Course contentsShow
← Cloud and Infrastructure
Lesson 1217 of 2,98924. Kubernetes NetworkingFree lesson

Service Traffic Policies

Controlling traffic routing with externalTrafficPolicy and internalTrafficPolicy settings.

Service Traffic Policies

What you'll learn: How Kubernetes Services route traffic differently based on externalTrafficPolicy and internalTrafficPolicy settings.

Why Traffic Policies Matter

When a Service receives traffic, Kubernetes must decide which Pods handle that traffic and whether to preserve information about where the request originated. Traffic policies give you control over these routing decisions.

Think of it like a mail-sorting facility: should letters be delivered to the closest branch (faster but less fair), or distributed evenly across all branches (fairer but potentially slower)?

externalTrafficPolicy

This policy controls traffic coming from outside your cluster (via NodePort or LoadBalancer Services):

  • Cluster (default): Traffic can be routed to any Pod on any node. The source IP is often hidden (SNAT'd). Load is balanced evenly.
  • Local: Traffic only goes to Pods on the same node where it arrived. Preserves the client's source IP. If no local Pods exist, the connection fails.

Use Local when you need to see real client IPs (for logging, security) or want to avoid extra network hops between nodes.

internalTrafficPolicy

This policy controls traffic from within the cluster (Pod-to-Service calls):

  • Cluster (default): Traffic distributed to all matching Pods cluster-wide.
  • Local: Traffic only routed to Pods on the caller's node.

Use Local to reduce latency and cross-node bandwidth when co-located Pods exist.

Trade-offs

Local policies improve performance and preserve source IPs but can create uneven load distribution. If a node has no matching Pods, requests fail or skip that node entirely.

Key Takeaway: Use externalTrafficPolicy: Local to preserve client IPs and reduce hops for external traffic, and internalTrafficPolicy: Local to optimize internal cluster communication when Pods are co-located.