Your app needs the real client IP behind a Kubernetes LoadBalancer service. What do you do?
IntermediateScenarioKubernetes Networking
Answer
Situation read → kube-proxy SNATs traffic when it forwards across nodes, hiding the client IP.
What I'd do →
- Set
externalTrafficPolicy: Localon the Service, which sends traffic only to nodes with local pods and keeps the source IP - The cloud health check then marks nodes without pods unhealthy automatically
- Or use PROXY protocol or
X-Forwarded-Foron an L7 LB - Verify by logging the remote address in the app
- Spread pods across nodes with topology spread constraints
Why → Cluster policy balances evenly but loses the client IP; Local keeps it with possible imbalance.
Interview tip → Say the trade-off is uneven load.
More on Kubernetes Networking
Explain the Kubernetes networking model in one minute.BeginnerClusterIP, NodePort and LoadBalancer: when do you use each?BeginnerHow does a pod find another service by name?BeginnerService versus Ingress: what is the difference?BeginnerWhat does a CNI plugin do and which ones do you know?BeginnerHow do you reach a pod from your laptop for debugging without exposing it?Beginner