Networking: Services, DNS, Ingress and policies · 6 MIN READ

Debugging traffic end to end: latency, saturation, errors and rollbacks

Follow a request from client to container port, read latency, saturation and error signals under load, and fix an overloaded Service and a bad release with scaling and kubectl rollout undo.

"The site is down" can mean a failure at any hop: DNS, the Ingress, the Service, its endpoints, pod readiness, the container port or the code. Each hop fails with its own signature, and the fastest debugging walks the path in order instead of guessing. This lesson builds that order and practises it on a Service under load.

kubernetes · A MAP OF THE IDEA

  1. Scope the symptom
  2. Walk name, entry, endpoints
  3. Check load: p99 and CPU
  4. Recent rollout? Undo first

Useful when

  • A fixed order finds most faults in a few commands.
  • Refused, timeout, 404, 503 and 500 each point at a hop.

Watch out

  • Readiness does not catch a version that is ready and wrong.
  • CPU limits throttle pods long before they report errors.

Implementation & operation cost: Load tests and dashboards for p99, errors and saturation, plus the discipline to roll back before debugging.

01

The path of one request

From outside, a request resolves a public name, reaches a load balancer or node port, and enters the ingress controller, which matches host and path, picks a pod from the Service's endpoints and connects to that pod's IP and container port. From inside, a pod resolves the Service name through CoreDNS and connects to the ClusterIP, and kube-proxy on its own node rewrites the destination to a ready pod. Every hop has a typical failure: NXDOMAIN for a wrong name or namespace, an nginx 404 when no rule matches, an nginx 503 or connection refused when there are no ready endpoints, refused despite endpoints for a wrong targetPort, a timeout for a NetworkPolicy or a dead node, and 5xx from the code itself.

02

Latency, saturation and errors

Three signals describe a service under load. Latency: watch the p99, not only the median, because queueing hits the tail first. Saturation: how close each pod is to its limit; a container at its CPU limit is throttled by the kernel's CFS quota, so it slows down long before it fails, and kubectl top pods shows usage pinned near the limit. Errors: the share of 5xx responses, timeouts and refused connections. Under growing load they move in a typical order: p99 climbs, then the median, then errors appear as queues overflow and the app or a proxy sheds load with 503. A bad release looks different: latency and saturation stay normal, and errors sit at a steady percentage from the moment the new pods became ready.

03

Reading traffic run

In the GopherForge lab terminal, traffic run sends simulated requests from a client inside the cluster while virtual time advances, so controllers, probes and rollouts keep working during the run. Each row covers one interval: REQ/S is the offered rate per second, OK, 5XX and FAILED count the requests of that interval, P50 and P99 are latencies, and READY PODS is ready over all endpoints behind the Service. The summary splits responses by status, shows how requests spread over pods and prints hints. FAILED means no HTTP answer at all, a refused or timed-out connection, which points at endpoints, ports or policies rather than at the code. Load tools for real clusters, such as k6, hey or vegeta, report the same quantities.

bash
traffic run svc/web --rps 400 --duration 20s
kubectl top pods
Read the code

Against one pod with a 250m CPU limit, the first interval shows 400 OK and 400 503, and from +4s every row shows 0 OK and 800 503 with P50 around 233ms while READY PODS stays 1/1. The pod is ready and saturated, not broken. The summary reads "Total 8000 requests · 5.0% ok" and suggests kubectl top pods, which shows the pod at 240m of its 250m limit.

04

Readiness keeps a rollout clean under load

A rolling update replaces pods while traffic flows. The readiness probe decides when a new pod joins the endpoints, so with a probe on a real readiness endpoint no connection reaches a container that is still starting; without a probe, a pod counts as ready as soon as its process starts. maxSurge and maxUnavailable, 25% each by default, bound how much capacity is in flight, so size replicas to carry the load with one pod missing. Requests and limits matter for traffic too: the CPU limit caps how much each pod can serve before it saturates, and the request is what the scheduler and an HPA reason about. Readiness only protects against pods that are not ready; a version that is ready and wrong still gets its share of the traffic.

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: gopherforge/web:v1
        ports:
        - name: http
          containerPort: 8080
        readinessProbe:
          httpGet:
            path: /readyz
            port: http
          periodSeconds: 2
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 250m
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
  - port: 80
    targetPort: http
Read the code

The Deployment starts with one replica, a CPU request and limit of 250m, and a readiness probe on /readyz every two seconds through the named port http. The Service uses targetPort: http, so the port number lives in one place. This is the starting point of the lab: deliberately one small pod, so that saturation is easy to see.

05

A triage checklist

Walk the path in order and stop at the first surprise. 1. Scope: one client or all, one path or all, since when, and what changed, from kubectl rollout history and recent events. 2. Name: nslookup from a pod in the caller's namespace. 3. Entry: through an Ingress, an nginx 404 means no rule and a 503 means no ready endpoints. 4. Service: kubectl get endpoints; empty means selector or readiness, a wrong port means targetPort. 5. Pods: readiness, restarts, events and logs. 6. Policy: timeouts instead of refusals suggest a NetworkPolicy or a dead node. 7. Load: kubectl top pods and the p99; saturated pods need more replicas or an HPA. 8. Release: errors that start with a rollout mean kubectl rollout undo first and investigation second.

bash
kubectl get pods -l app=web -o wide
kubectl get endpoints web
kubectl describe svc web
kubectl get events --types=Warning
kubectl logs deploy/web --tail=20
kubectl top pods
kubectl rollout history deploy/web
Read the code

Run these top to bottom against the web Deployment: pods and their nodes, the endpoints the Service really uses, the port mapping, warning events, recent logs, CPU usage against limits, and the revision history that rollout undo walks back through. Most incidents are explained before the last line.

06

Try it in the lab terminal

Start from the single small pod above and send it 400 requests per second, more than a 250m CPU limit can serve. Confirm the saturation with kubectl top, scale out, then roll out v2 under the same load and watch readiness keep errors at zero. Then ship gopherforge/web:v2-bug, which fails a quarter of its requests while passing every probe, read the error signature, and roll it back.

bash
kind create cluster
cat > web.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: gopherforge/web:v1
        ports:
        - name: http
          containerPort: 8080
        readinessProbe:
          httpGet:
            path: /readyz
            port: http
          periodSeconds: 2
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 250m
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
  - port: 80
    targetPort: http
EOF
kubectl apply -f web.yaml
kubectl rollout status deploy/web
traffic run svc/web --rps 400 --duration 20s
kubectl top pods
kubectl scale deploy/web --replicas=4
kubectl rollout status deploy/web
kubectl set image deploy/web web=gopherforge/web:v2
traffic run svc/web --rps 400 --duration 30s
kubectl set image deploy/web web=gopherforge/web:v2-bug
traffic run svc/web --rps 400 --duration 30s
kubectl rollout undo deploy/web
traffic run svc/web --rps 400 --duration 20s
Read the code

One pod at 400 req/s ends with "Total 8000 requests · 5.0% ok", mostly 503s, and kubectl top pods shows 240m against the 250m limit. With four replicas, the v2 rollout runs under the same load: READY PODS moves through 3/5 and 4/5 to 4/4 and the run reads "Total 12000 requests · 100.0% ok". The v2-bug rollout passes readiness, yet the 5XX column climbs to about a quarter of each interval and the run ends near 77.5% ok with "500 2633". After rollout undo the 500s fade as the bad pods drain, and the last rows show no errors.

TAKE THIS WITH YOU

Walk the request path in order: name, entry, endpoints, readiness, policy, load, release. Saturation shows as a rising p99 and 503s and is fixed with capacity; a bad release shows as a steady error rate from the rollout on and is fixed first with kubectl rollout undo.

Check your understanding

Right after a rollout, about 25% of requests return HTTP 500 while latency and CPU look normal and all pods are Ready. What should you do first?

Go to the source

Progress stays in this browser. No account needed.