Sub topic 11
Debugging a broken Ingress
This chapter assumes you can write Ingress manifests, know how an Ingress controller reads them, and understand Services and endpoints. It gives you an order of checks for finding why traffic does not arrive.
How to approach a failure
A request passes through several layers. Each one fails in a different way, so work from the outside in and find the first layer that is wrong.
Step 1: Check the Ingress object
Start with the resource itself.
kubectl get ingress shop
kubectl describe ingress shop
kubectl get ingressclass
kubectl get endpoints api webRead the output for these things:
- ADDRESS column. An empty address usually means no controller has picked up the Ingress.
- Backends in
describe. Each rule should list the Service and the Pod IPs behind it. A backend shown as<error: endpoints "api" not found>points to a wrong Service name. - Events. Controllers often write errors here, such as a missing TLS Secret.
- IngressClass list. The class named in
ingressClassNamemust exist.
Step 2: Match the symptom to a cause
| Symptom | Likely cause | What to check |
|---|---|---|
| No ADDRESS | No controller installed, or `ingressClassName` names a class no controller serves | `kubectl get ingressclass`, controller Pods running |
| 404 from the controller | Host or path does not match any rule, or the request has no matching Host header | Rule `host`, `path`, `pathType` |
| 404 from your app | Path reached the app but the app does not serve it | App routes, rewrite settings |
| 503 | Service has no ready endpoints | `kubectl get endpoints`, Service selector, readiness probes |
| 502 or 504 | Pod is reachable but fails or is slow | Pod logs, `targetPort`, timeouts |
| Certificate warning | Wrong Secret, wrong hostname, or default certificate served | `tls.hosts`, Secret name and namespace |
Common causes in detail
Wrong or missing class
If ingressClassName is absent and no default class is set, many controllers ignore the Ingress. If it names a class that does not exist, the same happens. Fix the name, or mark one IngressClass as the cluster default.
Path type surprises
With Prefix, /api matches /api and /api/v1, but not /apis. With Exact, /api does not match /api/. If a request returns the default 404, compare the exact URL you send against the pathType. Also remember that the longest matching path wins, so /api takes priority over /.
Services without endpoints
An Ingress can look correct while its Service selects nothing. The usual reasons are a selector that does not match the Pod labels, Pods that are not Ready, or a targetPort that does not match the container port.
kubectl get endpoints web
kubectl get pods --show-labelsAn empty ENDPOINTS column confirms the problem.
TLS problems
The Secret must be of type kubernetes.io/tls and in the same namespace as the Ingress. If the Secret is missing, the controller usually falls back to its default certificate, and browsers show a warning. Also check that the certificate covers the host in the request.
kubectl get secret shop-example-tls
kubectl describe secret shop-example-tlsTest around DNS
Before blaming the cluster, send a request straight to the controller with an explicit Host header. Replace ADDRESS with the value from kubectl get ingress.
curl -i -H "Host: shop.example.com" http://ADDRESS/apiIf this works but the browser does not, DNS is the problem.
Step 3: Read the controller logs
When the object looks correct, the controller logs show what it did with it. Find the controller Pods, then read their logs. Look for configuration reload errors, rejected annotations, and upstream connection failures.
kubectl get pods -A | grep -i ingress
kubectl logs -n NAMESPACE POD_NAMEReplace NAMESPACE and POD_NAME with the values from the first command.
Exercises
Exercise
An Ingress has no ADDRESS and the controller Pods are running. Name two things to check.
Show answer
Check that ingressClassName names an IngressClass that exists (kubectl get ingressclass), and that this class is served by the running controller. Also read the Ingress events with kubectl describe ingress for errors.
Exercise
Requests to shop.example.com return 503. kubectl describe ingress shows the backend with no Pod IPs. What is the likely cause and how do you confirm it?
Show answer
The Service has no ready endpoints. Run kubectl get endpoints web to see whether it is empty, then compare the Service selector with the Pod labels and check that the Pods are Ready and that targetPort matches the container port.