Packet Classification by Destination

A Pod sends a packet to one address, and the address alone decides if it goes to a Service, another Pod or the internet. What tells the three apart, in what order are the checks made, and what is done to each?

Play the animation 5 steps, animated, plays on a computer or a tablet

Packet Classification by Destination diagram: Packet classification on a Node in the default iptables proxy mode

Packet Classification by Destination, step by step

  1. A packet leaves the Pod carrying one destination and naming no machinery. In the default iptables proxy mode two stations stand between the packet and the wire, in a fixed order, and only the second is a routing decision. The nat table comes first.

    Play from step 1
  2. The destination 10.96.0.20:80 is a Service address from the Service range, and the nat table holds a rule for this address. The rule rewrites it to a backend Pod address, 10.244.2.7:8080 on Node-2.

    Play from step 2
  3. The route lookup reads the rewritten address, which now sits inside the Pod range, and here that range is cut into a slice per Node. So the packet goes to the Node owning 10.244.2.0/24, with no further rewrite.

    Play from step 3
  4. A packet sent straight to another Pod walks the same two stations in the same order. The nat table holds no rule for this address and passes the packet straight through, and the route lookup returns the same verdict.

    Play from step 4
  5. 1.1.1.1 falls in no cluster range, so the last resort takes it, the default route off the Node. The masquerade rules of the CNI plugin or ip-masq-agent keep the source for destinations in the non-masquerade ranges, the Pod range among them. 1.1.1.1 is in none of them, so the source becomes the Node IP.

    Play from step 5

Sources