Kubernetes Traffic Policies Explained: Cluster vs Local
Kubernetes Traffic Policies Explained: Cluster vs Local
By default, when traffic hits a Kubernetes Service, Kubernetes picks a healthy Pod at random anywhere in your cluster.
In a small cluster with two nodes sitting side by side, you probably will not notice. But in a larger cluster — especially one spread across multiple Availability Zones or regions — sending a request from Node A all the way to a Pod on Node C adds unnecessary network hops, extra latency, and cross-zone data transfer costs.
Kubernetes Traffic Policies let you tell kube-proxy whether traffic should roam across the whole cluster or stay strictly on the local node.
The Quick Mental Model
Think of the two policy options like this:
Cluster(Default): “Send the request to any ready Pod in the cluster.”
Load is spread evenly across all Pods, even if the request has to jump to another node.Local: “Only send the request to a Pod on the same node that received the traffic.”
Zero cross-node hops and lower latency — but if that node has no ready Pod, the request is dropped instead of forwarded elsewhere.
flowchart LR
subgraph ClusterMode ["Cluster Policy (Default)"]
direction TB
C_Req["Request arrives on Node 1"] --> C_KP["kube-proxy<br/>Picks any ready Pod in cluster"]
C_KP --> C_P1["Pod on Node 1"]
C_KP --> C_P2["Pod on Node 2 (extra network hop)"]
C_KP --> C_P3["Pod on Node 3 (extra network hop)"]
end
subgraph LocalMode ["Local Policy (Proximity First)"]
direction TB
L_Req["Request arrives on Node 1"] --> L_KP{"Ready Pod on<br/>Node 1?"}
L_KP -- Yes --> L_P1["Pod on Node 1<br/>(Fast, no extra hop)"]
L_KP -- No --> L_Drop["Request Dropped<br/>(Never forwarded to Node 2)"]
end
style ClusterMode fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#f8fafc
style C_Req fill:#1e293b,stroke:#94a3b8,color:#f8fafc
style C_KP fill:#1e1b4b,stroke:#818cf8,color:#f8fafc
style C_P1 fill:#064e3b,stroke:#10b981,color:#f8fafc
style C_P2 fill:#1e293b,stroke:#38bdf8,color:#f8fafc
style C_P3 fill:#1e293b,stroke:#38bdf8,color:#f8fafc
style LocalMode fill:#0f172a,stroke:#f59e0b,stroke-width:2px,color:#f8fafc
style L_Req fill:#1e293b,stroke:#94a3b8,color:#f8fafc
style L_KP fill:#312e81,stroke:#818cf8,color:#f8fafc
style L_P1 fill:#064e3b,stroke:#10b981,color:#f8fafc
style L_Drop fill:#450a0a,stroke:#ef4444,color:#f8fafc
1. Default Traffic Policy: Cluster
Cluster is the built-in default in Kubernetes.
When a request reaches your Service, kube-proxy distributes traffic across all ready endpoints (Pods) in the entire cluster, regardless of which node they live on.
- The Good: Traffic is balanced evenly across every Pod, and as long as at least one Pod is healthy somewhere in the cluster, requests succeed.
- The Trade-off: Because
kube-proxyignores node location, traffic often hops from one node (or Availability Zone) to another, adding latency. For external traffic, that extra hop also rewrites the source IP via SNAT (Source NAT), so your app sees the node’s IP instead of the real user’s IP.
2. Local Traffic Policy: Local
Local optimizes for speed and proximity.
When set to Local, kube-proxy restricts routing strictly to Pods running on the same node — either the node where the calling Pod lives (internal traffic) or the node that received the request from a NodePort / LoadBalancer (external traffic).
- The Good:
- Lower latency: No extra network hops between nodes.
- Preserves Client Source IP (for external traffic): Because traffic doesn’t bounce to another node, your app sees the real client IP address.
- The Trade-off (Important!):
- If there are no ready Pods on that node,
kube-proxywill not forward the request to Pods on other nodes. The traffic gets dropped.
- If there are no ready Pods on that node,
Rule of thumb for
Local: Only useLocalwhen you know healthy Pods will be available on the nodes receiving traffic — or when your cloud Load Balancer uses health checks to skip nodes with zero Pods.
Internal vs. External Traffic Policies
Kubernetes separates traffic into two paths, and gives you an independent setting for each:
internalTrafficPolicy— Controls Pod-to-Pod traffic inside the cluster (viaClusterIP).externalTrafficPolicy— Controls outside-to-cluster traffic coming throughNodePortorLoadBalancer.
flowchart TB
ExtUser["External User<br/>(Internet / LoadBalancer)"] -->|"NodePort or LoadBalancer<br/>Controlled by externalTrafficPolicy"| NodeA["Worker Node A"]
IntPod["Calling Pod<br/>(Inside Cluster)"] -->|"ClusterIP Service<br/>Controlled by internalTrafficPolicy"| NodeA
NodeA -->|"Local: Stay on Node A<br/>(Keeps client IP, 0 hops)"| PodA["Backend Pod on Node A"]
NodeA -.->|"Cluster: May hop to Node B<br/>(SNAT replaces client IP)"| PodB["Backend Pod on Node B"]
style ExtUser fill:#1e293b,stroke:#38bdf8,color:#f8fafc
style IntPod fill:#1e293b,stroke:#a855f7,color:#f8fafc
style NodeA fill:#1e1b4b,stroke:#818cf8,stroke-width:2px,color:#f8fafc
style PodA fill:#064e3b,stroke:#10b981,color:#f8fafc
style PodB fill:#451a03,stroke:#f59e0b,color:#f8fafc
Side-by-Side Comparison
| Policy Field | Cluster (Default) |
Local |
|---|---|---|
internalTrafficPolicy (Pod → Service) |
Sends Pod requests to any ready Pod across any node. Even load balancing, possible cross-node latency. | Sends Pod requests only to Pods on the same node. Lowest latency, drops if no local Pod exists. |
externalTrafficPolicy (User/LB → Node) |
Sends external requests to any ready Pod in the cluster. Client source IP is lost (replaced by node IP via SNAT). | Sends external requests only to Pods on the receiving node. Client source IP is preserved, drops if no local Pod exists. |
Configuring Traffic Policies (YAML Example)
You configure both fields directly inside a Service manifest under spec. Here is an example setting both to Local:
apiVersion: v1
kind: Service
metadata:
name: traffic-svc
spec:
selector:
app: backend
ports:
- protocol: TCP
port: 80
targetPort: 5000
internalTrafficPolicy: Local
externalTrafficPolicy: Local
You don’t have to set both!
internalTrafficPolicyandexternalTrafficPolicyare completely independent. For instance, it is very common to setexternalTrafficPolicy: Local(to keep real client IPs at the ingress/load balancer) while leavinginternalTrafficPolicy: Cluster(so internal microservices can still reach any healthy replica across the cluster).
Breaking Down Each Option
internalTrafficPolicy (Inside the Cluster)
Cluster(default): Traffic from a calling Pod is distributed across all available endpoints in the cluster, regardless of node. Ensures even load distribution, but can add latency from cross-node hops.Local: Traffic stays strictly on the same node as the requesting Pod. Cuts latency, but drops requests if no healthy endpoint exists on that node.
externalTrafficPolicy (Outside the Cluster)
Cluster(default): External traffic entering a node viaNodePortorLoadBalancercan be forwarded to any ready Pod on any node.Local: External traffic stays on the exact node that received it. Reduces latency and preserves the client’s original IP address, but fails if that node has no ready endpoints.
How to Use Local Safely Without Dropping Requests
If you want the speed (or source IP preservation) of Local without risking dropped traffic, pair your Service with one of these patterns:
- Run a
DaemonSet: Ensures every node in your cluster (or node pool) always has one Pod running (very common for ingress controllers like NGINX or Traefik). - Use
LoadBalancerhealth checks: ForexternalTrafficPolicy: Local, Kubernetes exposes ahealthCheckNodePort. Cloud load balancers (like AWS NLB/ALB) ping that port and automatically stop sending external traffic to nodes that have zero ready Pods. - Spread Pods intentionally: Use
podAntiAffinityortopologySpreadConstraintsso your Deployment replicas don’t pile onto a single node.
Key Considerations Before Choosing
- Latency-sensitive applications:
Localshines for workloads where every millisecond matters — like real-time gaming, video streaming, or node-local caches/telemetry agents. - Need real client IPs (rate limiting, audit logs, geo-blocking): Use
externalTrafficPolicy: Localon your Ingress or LoadBalancer Service so SNAT doesn’t hide the user’s IP. - Geographic distribution: If users or nodes are spread far apart, pair
Clusterpolicy with edge locations or a Content Delivery Network (CDN) to keep traffic fast globally without risking node-level blackholes. - Application requirements & replica count: If your Deployment only has 2 replicas across a 10-node cluster,
internalTrafficPolicy: Localwill fail on 8 out of 10 nodes. Always match your traffic policy to how your Pods are actually scheduled.