Interview Prep/Kubernetes/Services, DNS, Ingress and NetworkPolicy

Endpoints exist, but `curl orders:80` returns `Connection refused`.

BeginnerTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer

Likely causes → The Service targetPort does not match the port the container listens on (e.g. targetPort: 80 while the app listens on 8080), or a named targetPort refers to a port name the container does not define.

Diagnose →

kubectl get svc orders -o jsonpath='{.spec.ports}'
kubectl get endpointslices -l kubernetes.io/service-name=orders -o jsonpath='{.items[*].ports}'
kubectl exec orders-x -- ss -lnt 2>/dev/null || kubectl debug -it orders-x --image=nicolaka/netshoot --target=app -- ss -lnt

Fix → Set targetPort to the real listen port, or better, to a named port defined on the container (name: http).

Prevent → Named ports everywhere, and a smoke test that curls the Service after deploy.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, DNS, Ingress and NetworkPolicy