Continuing my Kubernetes the Hard Way homelab build. Steps 01-10 are already done, this covers step 11.
Original guide: 11-pod-network-routes.md
Thoughts I had while doing this
If I understood this step correctly, we're setting up a way for pods on different nodes to talk to each other. As I noted back in step 09, each node's bridge only connects the pods on that node. This step fills the gap by hardcoding routes between the nodes, a method called direct IP routing. It's a fancy way of saying "if a node gets traffic for this pod subnet, send it to that node."
Each worker has its own pod subnet (from the POD_SUBNET column in machines.txt):
| Node | Pod subnet |
|---|---|
node-0 | 10.200.0.0/24 |
node-1 | 10.200.1.0/24 |
The routing table
machines.txt has the IP and pod subnet for each machine:
root@jumpbox:~/kubernetes-the-hard-way# cat machines.txt <SERVER_IP> server.kubernetes.local server <NODE_0_IP> node-0.kubernetes.local node-0 10.200.0.0/24 <NODE_1_IP> node-1.kubernetes.local node-1 10.200.1.0/24 Pulled each value into a shell variable:
root@jumpbox:~/kubernetes-the-hard-way# { SERVER_IP=$(grep server machines.txt | cut -d " " -f 1) NODE_0_IP=$(grep node-0 machines.txt | cut -d " " -f 1) NODE_0_SUBNET=$(grep node-0 machines.txt | cut -d " " -f 4) NODE_1_IP=$(grep node-1 machines.txt | cut -d " " -f 1) NODE_1_SUBNET=$(grep node-1 machines.txt | cut -d " " -f 4) } Add the routes
On the controller (server), a route to each worker's pod subnet:
root@jumpbox:~/kubernetes-the-hard-way# ssh root@server <<EOF ip route add ${NODE_0_SUBNET} via ${NODE_0_IP} ip route add ${NODE_1_SUBNET} via ${NODE_1_IP} EOF Pseudo-terminal will not be allocated because stdin is not a terminal. ... On node-0, a route to node-1's pod subnet:
root@jumpbox:~/kubernetes-the-hard-way# ssh root@node-0 <<EOF ip route add ${NODE_1_SUBNET} via ${NODE_1_IP} EOF Pseudo-terminal will not be allocated because stdin is not a terminal. ... And on node-1, a route to node-0's pod subnet:
root@jumpbox:~/kubernetes-the-hard-way# ssh root@node-1 <<EOF ip route add ${NODE_0_SUBNET} via ${NODE_0_IP} EOF Pseudo-terminal will not be allocated because stdin is not a terminal. ... The "Pseudo-terminal will not be allocated" message is expected here since the commands are fed in through a heredoc, so it isn't an error. Each worker only needs a route to the other worker's subnet, since its own subnet is already handled locally by its bridge.
Verification
Checked the routing table on each machine:
root@jumpbox:~/kubernetes-the-hard-way# ssh root@server ip route default via <GATEWAY_IP> dev eth0 proto static 10.200.0.0/24 via <NODE_0_IP> dev eth0 10.200.1.0/24 via <NODE_1_IP> dev eth0 <LAN_SUBNET> dev eth0 proto kernel scope link src <SERVER_IP> root@jumpbox:~/kubernetes-the-hard-way# ssh root@node-0 ip route default via <GATEWAY_IP> dev eth0 proto static 10.200.1.0/24 via <NODE_1_IP> dev eth0 <LAN_SUBNET> dev eth0 proto kernel scope link src <NODE_0_IP> root@jumpbox:~/kubernetes-the-hard-way# ssh root@node-1 ip route default via <GATEWAY_IP> dev eth0 proto static 10.200.0.0/24 via <NODE_0_IP> dev eth0 <LAN_SUBNET> dev eth0 proto kernel scope link src <NODE_1_IP> The new 10.200.x.0/24 routes show up on all three machines.
Summary
Step 11 added static routes so pods on different nodes can reach each other: the controller knows how to reach both pod subnets, and each worker knows how to reach the other worker's subnet.