Why does a pod's IP change and how do apps cope?
BeginnerScenarioServices, Ingress and DNS
Answer
Situation read → A developer hard-coded a pod IP in config.
What I'd do →
- Explain pods are ephemeral and get a new IP on recreation
- Use a Service DNS name instead
- For StatefulSets use the stable pod DNS name from the headless Service
- Check with
kubectl get pods -o widebefore and after deleting a pod
Why → Services provide a stable virtual IP and name over a changing set of pod IPs.
Interview tip → Short answer: "never address pods directly".
More on Services, Ingress and DNS
A Service has no endpoints. How do you find out why?BeginnerWhen do you use ClusterIP, NodePort, LoadBalancer and ExternalName?BeginnerTraffic to a Service works from some pods but times out from others. How do you debug it?AdvancedYou want to expose three HTTP services under one hostname with different paths. How?Intermediateingress-nginx returns 404 for a new host. What do you check?Intermediateingress-nginx returns 502 or 503 intermittently. What are the likely reasons?Intermediate