Skip to content
Network debugging for platform engineers · Chapter 19 of 21 Appendix A: The training ground after a reboot

Appendix A: The training ground after a reboot

Goal: After a reboot of the VM netz, restore the complete training ground (namespaces, services, firewall rules, route and cluster) and prove with one block that everything runs again · Duration: approx. 15 min · Prerequisite: Days 0–16 done once

You have typed everything here before; each section names the day on which the commands are explained. That is why the comments in the blocks are short.

What a reboot leaves behind

survives is gone
files: ~/www, ~/ndbg (nginx.conf, PKI, k8s manifests, Corefile), /etc/netns/*/resolv.conf namespaces client, router, web, db, bridges, veth cables, addresses, routes
packages, /etc/sysctl.d/99-kind.conf the units web-http, dns-router, web-nginx (started with systemd-run, only until the reboot)
Docker and the kind nodes (start on their own) NAT rules in router and netz (table ndbg), rules in DOCKER-USER and raw
everything in the cluster: pods, services, Corefile, Hubble Relay the route 10.1.0.0/24 on netz, the Hubble port forward

Docker itself sets ip_forward=1 and the FORWARD policy DROP at startup; that is why the training ground needs its rules in DOCKER-USER (Day 11).

A.1 Namespaces, cables, addresses (Day 0, Drills 3–6)

# on netz
# four namespaces, each with loopback
for n in client router web db; do sudo ip netns add $n; sudo ip -n $n link set lo up; done
# three bridges as switches
for b in br-a br-b br-s; do sudo ip link add $b type bridge; sudo ip link set $b up; done
# veth cables: VM end to the bridge, other end into the namespace
sudo ip link add a-client type veth peer name eth0 netns client
sudo ip link add a-router type veth peer name eth-a netns router
sudo ip link add b-router type veth peer name eth-b netns router
sudo ip link add b-web type veth peer name eth0 netns web
sudo ip link add b-db type veth peer name eth0 netns db
sudo ip link add s-web type veth peer name stor0 netns web
sudo ip link add s-db type veth peer name stor0 netns db
for p in a-client a-router; do sudo ip link set $p master br-a up; done
for p in b-router b-web b-db; do sudo ip link set $p master br-b up; done
for p in s-web s-db; do sudo ip link set $p master br-s up; done
# Addresses and bringing interfaces up
sudo ip -n client addr add 10.1.0.10/24 dev eth0
sudo ip -n client link set eth0 up
sudo ip -n router addr add 10.1.0.1/24 dev eth-a
sudo ip -n router addr add 10.2.0.1/24 dev eth-b
sudo ip -n router link set eth-a up
sudo ip -n router link set eth-b up
sudo ip -n web addr add 10.2.0.10/24 dev eth0
sudo ip -n web addr add 10.10.0.10/24 dev stor0
sudo ip -n web link set eth0 up
sudo ip -n web link set stor0 up
sudo ip -n db addr add 10.2.0.20/24 dev eth0
sudo ip -n db addr add 10.10.0.20/24 dev stor0
sudo ip -n db link set eth0 up
sudo ip -n db link set stor0 up
# Routes and forwarding in the router
sudo ip -n client route add default via 10.1.0.1
sudo ip -n web route add default via 10.2.0.1
sudo ip -n db route add default via 10.2.0.1
sudo ip netns exec router sysctl -w net.ipv4.ip_forward=1 > /dev/null

A.2 The way out (Day 0, Drill 7)

# on netz
sudo ip link add up0 type veth peer name wan0 netns router
sudo ip addr add 192.168.100.1/30 dev up0
sudo ip link set up0 up
sudo ip -n router addr add 192.168.100.2/30 dev wan0
sudo ip -n router link set wan0 up
sudo ip -n router route add default via 192.168.100.1
sudo sysctl -w net.ipv4.ip_forward=1 > /dev/null
# NAT in the router and on netz
sudo ip netns exec router nft add table ip nat
sudo ip netns exec router nft add chain ip nat postrouting '{ type nat hook postrouting priority srcnat; }'
sudo ip netns exec router nft add rule ip nat postrouting oifname wan0 masquerade
sudo nft add table ip ndbg
sudo nft add chain ip ndbg postrouting '{ type nat hook postrouting priority srcnat; }'
sudo nft add rule ip ndbg postrouting ip saddr 192.168.100.0/30 oifname eth0 masquerade

A.3 The services (Day 0 Drill 8, Day 6, Day 7)

# on netz
# Web server on port 80 (Day 0)
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
# DNS for firma.lab in the router (Day 6)
sudo systemd-run --unit=dns-router ip netns exec router dnsmasq --keep-in-foreground \
  --no-resolv --no-hosts --server=1.1.1.1 --local=/firma.lab/ \
  --listen-address=10.1.0.1 --bind-interfaces \
  --host-record=web.firma.lab,10.2.0.10 --host-record=db.firma.lab,10.2.0.20 \
  --log-queries --log-facility=-
# nginx with shop/api on 8080 and TLS on 8443 (Days 7 and 8)
sudo systemd-run --unit=web-nginx ip netns exec web nginx -c /home/ubuntu/ndbg/nginx.conf -g 'daemon off;'

Expected (the IDs differ):

Running as unit: web-http.service; invocation ID: e98dd87840284b6789e303fdb433a4e3
Running as unit: dns-router.service; invocation ID: 524e4808d2c84226a8772102089c53f8
Running as unit: web-nginx.service; invocation ID: 9c00b1c6aa384ff9a8d5befe05eb4961

If your user is not called ubuntu, adjust the paths. The certificates from Day 8 are valid for 90 days; if the training ground is older, reissue shop and api with the commands from Day 8, Drill 2, and restart web-nginx (sudo systemctl restart web-nginx).

A.4 Docker and the kind network (Day 11, Day 12)

# on netz
# Name of the bridge of the Docker network kind
BR=br-$(sudo docker network inspect kind -f '{{.Id}}' | cut -c1-12)
# Let namespace network ↔ internet and namespace network ↔ kind through Docker's FORWARD policy DROP
sudo iptables -I DOCKER-USER -i up0 -o eth0 -j ACCEPT
sudo iptables -I DOCKER-USER -i eth0 -o up0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -I DOCKER-USER -i up0 -o $BR -j ACCEPT
sudo iptables -I DOCKER-USER -i $BR -o up0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Docker already drops packets to container addresses from foreign interfaces in raw (Day 12, Challenge)
sudo iptables -t raw -I PREROUTING -i up0 -d 172.18.0.0/16 -j ACCEPT
# Route to the router so CoreDNS reaches the zone firma.lab (Day 13, Challenge)
sudo ip route add 10.1.0.0/24 via 192.168.100.2 dev up0

A.5 The cluster (Day 12)

The kind nodes start on their own with Docker. However, Docker assigns their addresses in the network kind anew: after a reboot, control plane and worker may have swapped addresses. Check first:

# on netz
# Address of each node in the Docker network kind
for n in ndbg-control-plane ndbg-worker; do echo "$n $(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $n)"; done
# at which address does Cilium look for the API server?
helm -n kube-system get values cilium | grep k8sServiceHost

Expected (the addresses may be swapped):

ndbg-control-plane 172.18.0.3
ndbg-worker 172.18.0.2
k8sServiceHost: 172.18.0.2

If k8sServiceHost shows an IP that no longer belongs to the control plane, Cilium doesn’t find the API server: the Cilium pods stay at Init, all other pods hang in Unknown with “unable to connect to Cilium agent”. On Day 12 the cilium CLI turned the name ndbg-control-plane into a fixed IP during installation. With cilium upgrade the name stays; Docker always resolves it inside the nodes to the current address:

# on netz
# Name instead of IP, keep all other values
cilium upgrade --version 1.20.5 --reuse-values --set k8sServiceHost=ndbg-control-plane 2>&1 | grep -E "⚠️"
kubectl -n kube-system rollout restart daemonset/cilium deployment/cilium-operator
kubectl -n kube-system rollout status daemonset/cilium --timeout=5m | tail -1
helm -n kube-system get values cilium | grep k8sServiceHost

Expected:

⚠️  You maybe need to restart Cilium pods for configmap changes to take effect
daemonset.apps/cilium restarted
deployment.apps/cilium-operator restarted
daemon set "cilium" successfully rolled out
k8sServiceHost: ndbg-control-plane

You only have to do this once; after that the cluster survives every reboot. The remaining pods come back on their own as soon as Cilium runs. The kubelet retries with a growing pause, which can take a few minutes:

# on netz
# check every 10 s until no pod is in any state other than Running
until [ "$(kubectl get pods -A --no-headers | grep -vc Running)" = 0 ]; do sleep 10; done
kubectl get nodes

Expected:

NAME                 STATUS   ROLES           AGE   VERSION
ndbg-control-plane   Ready    control-plane   15h   v1.37.0
ndbg-worker          Ready    <none>          15h   v1.37.0

If the nodes swapped their addresses, the addresses in some outputs of Days 12–16 change as well (e.g. 172.18.0.3 for the NodePort). A NodePort responds on every node; simply use the address of either one.

A.6 Hubble (Day 14)

# on netz
cilium hubble port-forward > /dev/null 2>&1 &
sleep 3
hubble status | grep Connected

Expected:

Connected Nodes: 2/2

Checkpoint

The same block as in the playing field of Day 16, each line one layer:

# on netz
C="sudo ip netns exec client"
W="kubectl exec werkzeug --"
$C ping -c1 -W1 -q web.firma.lab | grep -o "1 received"
$C curl -s -m3 -o /dev/null -w "http %{http_code}\n" http://web.firma.lab/
$C curl -s -m3 -o /dev/null -w "tls %{http_code}\n" --cacert ~/ndbg/pki/ca-chain.crt --resolve shop.firma.lab:8443:10.2.0.10 https://shop.firma.lab:8443/
$W curl -s -m3 http://web/hostname | cut -c1-3
$C curl -s -m3 http://172.18.0.3:30080/hostname | cut -c1-3
$W dig +short web.firma.lab

Expected:

1 received
http 200
tls 200
web
web
10.2.0.10

The last line checks the whole path from Day 13: pod → CoreDNS → stub domain → route on netz → router → dnsmasq.

Tear everything down

When you no longer need the training ground:

# on netz
kind delete cluster --name ndbg
for s in web-http dns-router web-nginx; do sudo systemctl stop $s; done
for n in client router web db; do sudo ip netns del $n; done
sudo ip link del br-a; sudo ip link del br-b; sudo ip link del br-s; sudo ip link del up0
sudo nft delete table ip ndbg
sudo ip route del 10.1.0.0/24 2>/dev/null
sudo iptables -F DOCKER-USER
sudo iptables -t raw -D PREROUTING -i up0 -d 172.18.0.0/16 -j ACCEPT

Delete ~/ndbg, ~/www and /etc/netns/ by hand if you no longer need the files either.

Contents

More