Skip to content
Network debugging for platform engineers · Chapter 21 of 21 Appendix C: Final exam

Appendix C: Final exam

Goal: Find and fix ten faults from across the course in 120 minutes, each with the cause in one sentence and a proof command, and score yourself · Duration: 120 min · Prerequisite: Days 0–16, training ground in the state of the checkpoint of Appendix A

Rules of the Game

  • Time: 120 minutes, set a timer. Each task counts 10 %.
  • There is no certificate for this. Your own bar: from 70 %, your troubleshooting is solid.
  • An examiner, a colleague or you yourself without looking, runs the block of each task before it (copy, paste into a second terminal, close the window). The task names only the symptom.
  • Allowed: --help, man, the official documentation of the tools. Not allowed: this course during the exam, which includes the troubleshooting catalog in Appendix B.
  • A task only counts with the cause in one sentence, a proof command and a fix after which the checkpoint of Appendix A is fully green again. Whoever removes the symptom (flushes the firewall, deletes policies, rebuilds a namespace, restarts pods) gets 0 %.
  • The tasks are independent of each other; the order is up to you. Solutions are at the end.

Shortcuts for the whole exam:

# on netz
C="sudo ip netns exec client"
W="kubectl exec werkzeug --"

Task 1: db is gone (10 %)

Examiner:

# on netz
sudo ip -n db link set eth0 down

Symptom: $C ping -c2 -W1 10.2.0.20 – no answer. Fix it so that db is reachable again.

Task 2: Sometimes yes, sometimes no (10 %)

Examiner:

# on netz
sudo ip -n db addr add 10.2.0.10/24 dev eth0

Symptom: http://10.2.0.10/ sometimes returns 200, sometimes nothing at all. Restarting the router “helps” briefly.

Task 3: The short name (10 %)

Examiner:

# on netz
echo "nameserver 10.1.0.1" | sudo tee /etc/netns/client/resolv.conf > /dev/null

Symptom: A script in the namespace client calls http://web/ and gets Could not resolve host: web. http://web.firma.lab/ works.

Task 4: But the service is running (10 %)

Examiner:

# on netz
sudo systemctl stop web-http
sudo systemd-run --unit=web-http --property=WorkingDirectory=/home/ubuntu/www \
  ip netns exec web python3 -m http.server 80 --bind 127.0.0.1 > /dev/null 2>&1

Symptom: $C curl http://web.firma.lab/ – no connection. “But the service is running,” says the web team, and systemctl status web-http proves them right.

Task 5: Only the shop (10 %)

Examiner:

# on netz
sudo ip netns exec router nft add table inet filter
sudo ip netns exec router nft add chain inet filter weiter '{ type filter hook forward priority 0; }'
sudo ip netns exec router nft add rule inet filter weiter ip daddr 10.2.0.10 tcp dport 8080 counter drop

Symptom: http://shop.firma.lab:8080/ (with --resolve to 10.2.0.10) hangs, http://web.firma.lab/ works.

Task 6: It works in the browser (10 %)

Examiner:

# on netz
sed -i '28s|shop-full.crt|shop.crt|' ~/ndbg/nginx.conf
sudo systemctl restart web-nginx

Symptom: A service that trusts only the root CA reports when fetching https://shop.firma.lab:8443/:

# on netz
$C curl -sS -m3 --cacert ~/ndbg/pki/root.crt --resolve shop.firma.lab:8443:10.2.0.10 https://shop.firma.lab:8443/ -o /dev/null
curl: (60) SSL certificate problem: unable to get local issuer certificate

“It works in the browser.”

Task 7: Sluggish (10 %)

Examiner:

# on netz
sudo ip netns exec router tc qdisc add dev eth-b root netem delay 300ms

Symptom: Every request to http://web.firma.lab/ takes more than half a second; before, it took milliseconds. Show where the time is lost, and fix it.

Task 8: All pods are running (10 %)

Examiner:

# on netz
for p in $(kubectl get pod -l app=web -o name); do kubectl exec $p -- rm /tmp/bereit; done
sleep 6

Symptom: $W curl http://web/hostname – Could not connect to server. kubectl get pods shows both web pods as Running.

Task 9: The internal zone (10 %)

Examiner:

# on netz
sudo ip route del 10.1.0.0/24

Symptom: In the cluster, web.firma.lab no longer resolves: SERVFAIL after several seconds. In the namespace client, the name works.

Task 10: Only the tools pod may (10 %)

Examiner:

# on netz
kubectl apply -f - > /dev/null <<'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: nur-werkzeug}
spec:
  podSelector: {matchLabels: {app: web}}
  policyTypes: [Ingress]
  ingress:
  - from:
    - podSelector: {matchLabels: {run: werkzeug}}
    ports:
    - {protocol: TCP, port: 80}
EOF

Symptom: The policy is supposed to allow exactly the tools pod access to web. Since it became active, the tools pod doesn’t get through either. The policy should stay; repair it.

Solutions

Solution 1

Cause: The interface eth0 in db is down, and with it the default route that ran over it has disappeared.

# on netz
sudo ip -n db -br link show eth0
ip -br link show b-db
sudo ip -n db link set eth0 up
# link back – is that enough?
sudo ip netns exec router arping -c2 -I eth-b 10.2.0.20 | grep bytes
$C ping -c2 -W1 -q 10.2.0.20 | grep -o "[0-9] received"
sudo ip -n db route

Expected (MAC differs):

eth0@if14        DOWN           5a:45:95:8a:b8:fe <BROADCAST,MULTICAST>
b-db@if2         DOWN           96:73:8e:6a:52:85 <NO-CARRIER,BROADCAST,MULTICAST,UP>
42 bytes from 5a:45:95:8a:b8:fe (10.2.0.20): index=0 time=18.808 usec
42 bytes from 5a:45:95:8a:b8:fe (10.2.0.20): index=1 time=11.596 usec
0 received
10.2.0.0/24 dev eth0 proto kernel scope link src 10.2.0.20
10.10.0.0/24 dev stor0 proto kernel scope link src 10.10.0.20

Switching it on earns half the points. Full points only come with the second step: the router reaches db on Layer 2, but the reply to 10.1.0.10 finds no path. When the link went down, the kernel deleted all routes via eth0, including the default route (Days 1 and 2).

# on netz
sudo ip -n db route add default via 10.2.0.1
$C ping -c2 -W1 -q 10.2.0.20 | grep -o "[0-9] received"

Expected:

2 received

Solution 2

Cause: db additionally carries the address 10.2.0.10. Two machines answer ARP, and the router picks one or the other.

# on netz
# Habets arping with -d: exit code 1 for two different MAC addresses
sudo ip netns exec router arping -d -c2 -I eth-b 10.2.0.10 > /dev/null; echo "Duplikat-Exit: $?"
# who else has the address?
for n in web db; do echo "$n: $(sudo ip -n $n -br addr show eth0)"; done
sudo ip -n db addr del 10.2.0.10/24 dev eth0
# drop the old entry in the router, then check again
sudo ip -n router neigh flush dev eth-b
sudo ip netns exec router arping -d -c2 -I eth-b 10.2.0.10 > /dev/null; echo "Duplikat-Exit: $?"

Expected (interface numbers and IPv6 addresses differ):

Duplikat-Exit: 1
web: eth0@if13        UP             10.2.0.10/24 fe80::24e1:fff:fe10:a8f9/64
db: eth0@if14        UP             10.2.0.20/24 10.2.0.10/24 fe80::5845:95ff:fe8a:b8fe/64
Duplikat-Exit: 0

db has no service on port 80: if the connection lands there, db rejects it. Hence “sometimes 200, sometimes nothing” (Day 3).

Solution 3

Cause: The resolv.conf of the namespace client lacks the line search firma.lab; without a search list, web is a name without a domain.

# on netz
# how the application asks (exit code 2 = not found)
$C getent ahosts web; echo "getent=$?"
cat /etc/netns/client/resolv.conf
echo "search firma.lab" | sudo tee -a /etc/netns/client/resolv.conf > /dev/null
$C curl -s -m3 -o /dev/null -w "%{http_code}\n" http://web/

Expected:

getent=2
nameserver 10.1.0.1
200

ip netns exec lays /etc/netns/<ns>/resolv.conf over /etc/resolv.conf, a file that is easy to forget (Day 6).

Solution 4

Cause: The web server listens only on 127.0.0.1 in the namespace web; from outside, nobody is listening on 10.2.0.10:80.

# on netz
$C curl -sS -m3 http://web.firma.lab/ -o /dev/null; echo "exit=$?"
sudo ip netns exec web ss -ltnp 'sport = :80'
sudo systemctl stop web-http
sudo systemd-run --unit=web-http --property=WorkingDirectory=/home/ubuntu/www \
  ip netns exec web python3 -m http.server 80 --bind 10.2.0.10
$C curl -s -m3 -o /dev/null -w "%{http_code}\n" http://web.firma.lab/

Expected (PID and ID differ):

curl: (7) Failed to connect to web.firma.lab port 80 after 3 ms: Couldn't connect to server
exit=7
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      5          127.0.0.1:80        0.0.0.0:*    users:(("python3",pid=20756,fd=3))
Running as unit: web-http.service; invocation ID: c6a64865c6504a05a2a6843aeea74057
200

Couldn't connect after 3 ms is an active rejection, not a timeout: the path is clear, but at the target nobody is listening on this address (Days 4 and 5).

Solution 5

Cause: A rule in the router’s forward chain drops TCP to port 8080 at 10.2.0.10.

# on netz
# is nginx listening? (yes)
sudo ip netns exec web ss -ltn 'sport = :8080' | tail -1
# which rules does the router have, and does one of them match?
sudo ip netns exec router nft list tables
sudo ip netns exec router nft list chain inet filter weiter | grep counter
sudo ip netns exec router nft delete table inet filter
$C curl -s -m3 -o /dev/null -w "%{http_code}\n" --resolve shop.firma.lab:8080:10.2.0.10 http://shop.firma.lab:8080/

Expected (counters differ):

LISTEN 0      511        10.2.0.10:8080      0.0.0.0:*
table ip nat
table inet filter
        ip daddr 10.2.0.10 tcp dport 8080 counter packets 3 bytes 180 drop
200

Timeout instead of rejection, the service is listening, and the counter of the DROP rule rises with every attempt: that is the proof (Day 9).

Solution 6

Cause: For shop, nginx sends only its own certificate without the intermediate CA; a client that trusts only the root cannot build the chain. Browsers often fill in missing intermediate certificates themselves.

# on netz
# which certificates does the server send? (s: = subject, 0 = its own, 1 = intermediate CA)
$C openssl s_client -connect 10.2.0.10:8443 -servername shop.firma.lab -showcerts -CAfile ~/ndbg/pki/root.crt </dev/null 2>/dev/null | grep -E "^ [0-9] s:|Verify return code"
grep -n "ssl_certificate " ~/ndbg/nginx.conf
sed -i '28s|shop.crt|shop-full.crt|' ~/ndbg/nginx.conf
sudo systemctl restart web-nginx
$C curl -s -m3 -o /dev/null -w "%{http_code}\n" --cacert ~/ndbg/pki/root.crt --resolve shop.firma.lab:8443:10.2.0.10 https://shop.firma.lab:8443/

Expected:

 0 s:CN = shop.firma.lab
Verify return code: 21 (unable to verify the first certificate)
28:        ssl_certificate     /home/ubuntu/ndbg/pki/shop.crt;
35:        ssl_certificate        /home/ubuntu/ndbg/pki/api-full.crt;
200

Only certificate 0. After the fix, the same command shows 0 and 1 s:CN = Firma Issuing CA (Day 8).

Solution 7

Cause: On the router’s interface eth-b, a netem queue delays every packet by 300 ms.

# on netz
# where does the time go? (values cumulative from the start, Day 7)
$C curl -s -m10 -o /dev/null -w "dns %{time_namelookup} connect %{time_connect} erstes-byte %{time_starttransfer}\n" http://web.firma.lab/
# segment by segment: up to the router, then up to web
$C ping -c3 -q 10.1.0.1 | tail -1
$C ping -c3 -q 10.2.0.10 | tail -1
# what is attached to the interface toward web?
sudo ip netns exec router tc qdisc show dev eth-b
sudo ip netns exec router tc qdisc del dev eth-b root
$C curl -s -m10 -o /dev/null -w "connect %{time_connect} gesamt %{time_total}\n" http://web.firma.lab/

Expected (times differ slightly):

dns 0.002725 connect 0.303369 erstes-byte 0.608743
rtt min/avg/max/mdev = 0.103/0.128/0.142/0.018 ms
rtt min/avg/max/mdev = 300.360/300.422/300.490/0.053 ms
qdisc netem 8001: root refcnt 3 limit 1000 delay 300ms
connect 0.005793 gesamt 0.013613

DNS is fast, connect jumps by 300 ms, the first byte by another 300 ms: each round trip pays the delay once. The ping to the router is fast, to web slow, so the segment in between is to blame (Days 4 and 7).

Solution 8

Cause: The readiness probe of both web pods fails (/tmp/bereit is missing); pods that are not ready are not endpoints of the Service.

# on netz
kubectl get pods -l app=web
kubectl get endpointslices -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]} ready={.conditions.ready}{"\n"}{end}'
for p in $(kubectl get pod -l app=web -o name); do kubectl exec $p -- touch /tmp/bereit; done
sleep 5
$W curl -s -m3 http://web/hostname | cut -c1-3

Expected (pod names, restarts and IPs differ):

NAME                   READY   STATUS    RESTARTS      AGE
web-69856b5777-5jjjh   0/1     Running   1 (16m ago)   37m
web-69856b5777-zxppv   0/1     Running   1 (16m ago)   37m
10.244.1.72 ready=false
10.244.1.47 ready=false
web

Running means “the process is running”, READY 0/1 means “gets no traffic”. The EndpointSlice still lists the pods, but with ready=false (Day 12).

Solution 9

Cause: netz no longer has a route to the network 10.1.0.0/24; CoreDNS can’t reach the router’s dnsmasq for the stub domain firma.lab.

# on netz
time $W dig web.firma.lab | grep -E "status:|Query time"
ip route get 10.1.0.1 | head -1
sudo ip route add 10.1.0.0/24 via 192.168.100.2 dev up0
$W dig +short web.firma.lab

Expected (times differ):

;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 11666
;; Query time: 2005 msec

real    0m12.650s
user    0m0.203s
sys 0m0.080s
10.1.0.1 via 172.16.0.1 dev eth0 src 172.16.0.123 uid 1000
10.2.0.10

SERVFAIL after seconds is almost never CoreDNS itself, but an upstream that doesn’t answer. The packets go via the default route into the home network instead of to the router (Day 13).

Solution 10

Cause: The policy allows port 80, which is the port of the Service. At the pod, the packets arrive on 8080, and the policy doesn’t let that one through.

# on netz
hubble observe --from-pod default/werkzeug --verdict DROPPED --since 30s --last 1
kubectl get networkpolicy nur-werkzeug -o jsonpath='{.spec.ingress[0].ports}'; echo
kubectl get service web -o jsonpath='{.spec.ports[0].port} -> {.spec.ports[0].targetPort}'; echo
# replace the port with the name of the container port (JSON patch, op replace)
kubectl patch networkpolicy nur-werkzeug --type=json -p '[{"op":"replace","path":"/spec/ingress/0/ports/0/port","value":"http"}]'
$W curl -s -m3 http://web/hostname | cut -c1-3

Expected (time and pod name differ):

Nov 27 13:06:51.504: default/werkzeug:37048 (ID:1853) <> default/web-69856b5777-5jjjh:8080 (ID:8424) policy-verdict:none INGRESS DENIED (TCP Flags: SYN)
[{"port":80,"protocol":"TCP"}]
80 -> http
networkpolicy.networking.k8s.io/nur-werkzeug patched
web

If the Hubble port forward is no longer running, start it as in Appendix A (Day 14).

Scoring

Points Rating
90–100 % You find network faults faster than they get reported.
70–80 % Passed: method and tools are solid.
50–60 % The layers are clear, the measuring still takes time. Repeat the days of the tasks you missed.
below 50 % Play Day 16 again, then repeat the exam in a week.

Clean up

After the exam, remove the policy from Task 10 and run the checkpoint of Appendix A; it must be fully green:

# on netz
kubectl delete networkpolicy nur-werkzeug

Expected:

networkpolicy.networking.k8s.io "nur-werkzeug" deleted from default namespace

Contents

More