Ingress Vs Service¶
Introduction¶
This guide explains ingress vs service with practical kubectl commands, realistic output, and production-focused checks. Kubernetes networking issues usually involve selectors, endpoints, ports, DNS, ingress rules, CNI behavior, or NetworkPolicy.
When You Need This¶
Use this guide when pods are running but traffic does not reach them, DNS names do not resolve, ingress returns errors, or service endpoints are missing.
Example Configuration¶
apiVersion: v1
kind: Service
metadata:
name: web
namespace: app
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080
Step-by-Step Checks¶
kubectl get svc,endpoints -A
kubectl describe svc web -n app
kubectl get ingress -A
kubectl run curl --rm -it --image=curlimages/curl --restart=Never -- curl -I http://web.app.svc.cluster.local
kubectl get events -n app --sort-by=.lastTimestamp
Expected output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/web ClusterIP 10.96.42.10 <none> 80/TCP 2d
Verification¶
kubectl get endpoints web -n app
kubectl run curl --rm -it --image=curlimages/curl --restart=Never -- curl -I http://web.app.svc.cluster.local
Troubleshooting¶
Verify that service selectors match pod labels, targetPort matches the container port, endpoints exist, DNS resolves, and NetworkPolicy allows the traffic path.
Common Mistakes¶
- Creating a Service whose selector does not match any pod labels.
- Confusing port, targetPort, nodePort, and containerPort.
- Testing ingress before confirming the service works inside the cluster.
Quick Checklist¶
- Check pod labels.
- Check service selector and endpoints.
- Test DNS inside the cluster.
- Test service before ingress.
- Review NetworkPolicy and ingress-controller logs.
Related Guides¶
- Troubleshoot Service Not Working
- Troubleshoot Kubernetes DNS
- Network Policy Explained
- kubectl Port Forward
Summary¶
Kubernetes networking is easier when you test inside out: pod, service endpoint, DNS, policy, ingress, then external traffic.