Chapters

The mental model: Andromeda, no layer 2

Chapter 1.1 placed Kadé's resources in zones and regions. Inside them, the fundamentals course's picture of cables, switches, ARP broadcasts and a router at the door no longer holds. GCP keeps the addresses and the rules, but removes almost everything physical underneath. This chapter explains what replaces it, so the rest of the course makes sense.

Foundations · chapter 2 of 26 · 16 min read

Why GCP cannot use a normal network

Builds on32. Hubs, switches and routers9. ARP

Google has to give millions of unrelated customers each their own private network, running on the same shared physical machines, in data centres all over the world. Each customer must feel like they have a data centre of their own, and must never see anyone else's traffic.

The tools from the fundamentals course do not stretch that far:

#Normal network toolWhy it fails at Google's size
1A switch and one broadcast domain per networkYour VMs are spread over hosts in different zones. There is no single cable or switch they could all share
2VLANs to keep customers apartA VLAN ID has 12 bits, so there are only 4,094 usable IDs. Google has far more networks than that
3ARP broadcasts and MAC learningBroadcasts across a whole data centre would flood every host, and switch MAC tables would never be big enough
4Firewall and NAT boxes in the pathEvery packet would have to pass through a few boxes. They would become the slowest point and a single point of failure

So the picture you see (two VMs side by side in one subnet) and what is really there are very different:

what you seekade-vpc · sn-app · 10.10.1.0/24kade-api-110.10.1.10 · zone akade-api-210.10.1.11 · zone ba switch?looks like one LAN, one switch, one broadcast domainwhat is really therephysical host · zone akade-api-1data planeAndromedaphysical host · zone bkade-api-2data planeAndromedaGoogle's routers and links, which you never see
  • Run by Google
  • Your VPC

The subnet is not a place. It is a range of addresses and a set of rules, and Google's software makes VMs in it behave as if they were neighbours.

Wide by design - scroll it sideways.

Andromeda: a control plane and a data plane

The software that runs every VPC is called Andromeda. It has two parts, and the split between them explains almost everything in this chapter.

Andromeda control planethe record of every VM, IP, host, route and firewall rulepushes state down,before any packetphysical host A · zone akade-api-1anothercustomer's VMdata planestate loaded in advancephysical host B · zone bkade-api-2anothercustomer's VMdata planestate loaded in advancephysical host C · zone bkade-dbanothercustomer's VMdata planestate loaded in advance
  • Run by Google
  • Your VPC
  • Allowed traffic and replies

Kadé's VMs share hosts with other customers' VMs. The data plane on each host keeps them apart: it only ever hands a VM packets that belong to that VM's own network.

Wide by design - scroll it sideways.

#PartWhere it runsWhat it knowsWhat it does
1Control planeGoogle's own servers, one logical system for the worldEverything: every VM, IP, host, route, firewall ruleDecides; pushes the parts each host needs down to it
2Data planeEvery physical host, beside each vNICOnly what it was given: where each destination IP lives, which rules applyActs on every packet: check firewall, look up the destination host, wrap, send

Compare this with the home router in the fundamentals course. The home router was both at once: it held the routing table and it moved the packets. In GCP the thinking and the moving are split, and the moving is copied onto every host.

Nothing is discovered: it is all known in advance

Builds on27. DHCP9. ARP32. Switch MAC learning

This is the most important idea in the chapter. A normal LAN finds things out while it runs: DHCP hands out a free address, ARP asks who has an IP, and a switch learns which port each MAC is on by watching traffic.

GCP never needs to find anything out. When a VM is created, the control plane decides its IP and its host, and pushes that to every data plane that may need it. So there is no discovery, no flooding and no learning.

#JobHome LAN (fundamentals course)GCP
1Give a device an IPDHCP picks a free address from a pool (ch 27)Control plane picks it when the VM is created. DHCP only delivers it
2Find the MAC for an IPARP broadcast, the owner replies (ch 9)The data plane answers the VM itself; nothing is broadcast
3Know where a device isSwitch learns MAC → port from traffic (ch 32)Control plane already knows IP → host
4Decide if traffic is allowedOne firewall box at the edgeRules loaded into the data plane beside every VM
5Share one public IPNAT on the home router (ch 10)1:1 NAT done by the data plane on the VM's host

Follow one packet: kade-api-1 to kade-db

Builds on1. The envelopes8. MAC vs IP

kade-api-1 (zone a) runs a SQL query on kade-db (zone b). Step through what happens. Watch which parts change and which never do.

step 1 of 6
control planealready pushed: 10.10.2.5 is on host Bphysical host A · zone aphysical host B · zone bkade-api-110.10.1.10/32gw 10.10.1.1guest OSvNICdata plane Aegress firewalllook up hostwrapGoogle'snetworkdata plane Bunwrapingress firewalldelivervNICkade-db10.10.2.5/32port 5432guest OS

1 · The app sends

The Node app writes the query to its database socket. The kernel builds an IP packet. The destination is not inside the VM's /32, so the route table says: send it to the gateway.

Inner packet (TCP)
10.10.1.10:41822 → 10.10.2.5:5432
Route chosen
default via 10.10.1.1

Two things to take from this. First, the packet your VM builds (source 10.10.1.10, destination 10.10.2.5) arrives exactly as it was sent. Google puts it inside its own outer envelope to cross the physical network, then takes it back out. The VMs never see that envelope. Second, the MAC addresses in the frame are only there because the guest OS expects them. The data plane throws them away and routes on the IP.

kade-api-1 and kade-db are in different subnets, yet no step in the walk is a router hop. Between two subnets of one VPC the path is exactly the same as inside one subnet: the data plane on kade-api-1's host matches the subnet route and sends the packet straight to the host running kade-db. The only differences are which subnet route matched and which firewall rules apply (chapter 5.1).

What the VM sees: a /32 and one gateway

Builds on4. Subnet masks5. The default gateway

In the fundamentals course, the subnet mask decided everything: same network, send directly; different network, send to the gateway. GCP uses that same rule to switch direct sending off.

On Linux, DHCP gives the VM a /32 mask. A /32 network holds exactly one address, the VM itself. So to the VM, every other address is on a different network, even kade-api-2 in the same subnet. Everything goes to the gateway 10.10.1.1, and the only MAC the VM ever needs is the gateway's.

That gateway is not a machine. There is no router behind 10.10.1.1: it is an address the data plane on every host answers for (section 02). You cannot log in to it or find it in any list of resources. The VM's own route table stays simple, "send everything to .1", and the real decision is made by the VPC's route table (chapter 4).

Two things GCP fakes: ARP and DHCP

The VM runs an ordinary operating system that expects an ordinary Ethernet network. Instead of changing every OS, Google lets the guest do what it always does, and the data plane quietly answers.

ARP

The VM asks "who has 10.10.1.1?". The request never leaves the host. The data plane replies with a MAC (42:01:0a:0a:01:01), the VM builds its frame with it, and the data plane throws the MAC away and routes on the IP. Because no other VM ever hears an ARP request, one VM cannot answer for another. ARP spoofing, from the Fundamentals ch 9, cannot work here.

DHCP

The VM boots and runs a normal DHCP client. The answer comes from the metadata server (section 07), but there is no pool to choose from: the address was fixed by the control plane when the network card was created. DHCP is only the delivery van for a decision already made. That is why the lease always renews to the same address.

#DHCP deliversValue for kade-api-1Why it matters
1IP address and mask10.10.1.10/32Always the same; set by the control plane
2Gateway and routes10.10.1.1, plus the scope-link route to itSection 05
3DNS server169.254.169.254Internal names like kade-db.asia-southeast1-b.c.kade-prod.internal (chapter 8)
4MTU1460The VPC's MTU, the same on every VM (section 08)
5Host name and search domainskade-api-1, c.kade-prod.internal, …Short names work inside the VPC

The metadata server: 169.254.169.254

Builds on2. Link-local addresses

Every VM can reach 169.254.169.254, also known by the name metadata.google.internal. It is a link-local address: it is never routed anywhere, and the answer comes from Google's software for that VM, not from a machine out on the network. It does several jobs:

#JobWhat the VM getsChapter
1DHCP serverIP, routes, MTU, DNS server (section 06)1
2DNS resolverInternal VM names, private zones, and normal internet names8
3Time (NTP)Clock sync, as in the Fundamentals ch 27-
4Instance metadataIts own name, zone, IPs, tags, startup scripts3
5Access tokensShort-lived tokens for the VM's service account5

MTU: 1460, set on the whole VPC

Builds on18. MTU, MSS and fragmentation

In the fundamentals course, the MTU was a property of each link, usually 1500 on Ethernet. In GCP there are no links you manage, so the MTU is a setting on the VPC network. Every VM in kade-vpc gets the same value through DHCP.

The default is 1460, 40 bytes less than normal Ethernet. Google's own outer envelope (section 04) is added underneath your MTU, so it never eats into your 1460. So a full TCP segment inside kade-vpc carries:

1460 MTU − 20 IP − 20 TCP = 1420 MSS

Two ways MTU goes wrong in practice:

#MistakeWhat you seeChapter
1Someone hardcodes mtu 1500 inside a VM's OS while the VPC is 1460Small requests work; large responses or file copies hang. The same black hole as Fundamentals ch 181
2A VPN adds its own headers on top of 1460The same symptom across the VPN, unless MSS is lowered15

The firewall and external IPs live in the data plane too

Builds on10. NAT16. TCP connections

Because the data plane sits beside every VM, jobs that normally need a box in the middle are done there instead:

#JobHow GCP does itWhat follows from that
1FirewallRules are loaded into the data plane of every host. Outgoing (egress) rules are checked beside the sending VM, incoming (ingress) rules beside the receiving VMNo firewall box to size or to fail. A packet blocked by an egress rule never leaves the host. The firewall scales with the number of VMs
2Stateful firewallThe data plane remembers each allowed connection, like the NAT table in the fundamentals courseReplies to an allowed connection come back in without needing their own rule (chapter 5)
3External IP1:1 NAT on the VM's host: the external IP is swapped for the internal IP on the way in, and back on the way outThe VM's OS never sees its external IP. ip addr shows only the internal one (chapter 3)
4ChangesA new or edited rule must reach every data plane it affectsChanges take effect within seconds, not at once. After a change, wait a moment before testing

What you lose without layer 2, and what to use instead

A VPC is a layer 3 network: everything is routing, nothing is switching. Most apps never notice. Some things do:

#MissingWhat breaksUse instead
1Broadcast and multicastAnything that finds peers by broadcasting, such as some cluster discovery. It fails silentlyA fixed list of peers, DNS, or a discovery service
2VLANsNothing to configure; there are no tagsSeparate subnets, firewall rules, or separate VPCs
3Promiscuous modeYou cannot sniff other VMs' traffic; you only ever get your own packetsVPC Flow Logs or Packet Mirroring (chapter 16)
4Gratuitous ARP (used by VRRP, HSRP, CARP, keepalived)Moving a "floating IP" between two VMs by announcing it. The data plane ignores what the guest claimsAn internal load balancer with health checks, or move an alias IP range through GCP (chapter 3)
5Meaningful MAC addressesLicences or tools tied to a MAC. Nothing routes on MACs hereTie things to the VM name or IP instead
6A real layer 2 segmentOld clustering software or appliances that truly need oneTunnel layer 2 over layer 3 (VXLAN or GRE) inside the VPC

Some of these losses are also protections. Rogue DHCP servers and ARP spoofing are impossible, because no other VM ever hears the request.

Back to Kadé

Commands in this chapter

All read-only. Commands 2 to 6 run inside the VM after command 1.

Log in to a VM

  • What it shows: Opens an SSH session on kade-api-1 through IAP, without an external IP.
  • What to look for: If it fails, the firewall or IAM is blocking IAP. Chapter 6 covers both.
gcloud compute ssh kade-api-1 --zone=asia-southeast1-a --tunnel-through-iap

See the VM's address and MTU

  • What it shows: The IP, mask and MTU the VM got from DHCP.
  • What to look for: /32 on Linux, and mtu matching the VPC's MTU.
ip -4 addr show ens4

See the VM's routes

  • What it shows: Where the VM sends traffic.
  • What to look for: A scope link route to 10.10.1.1 and a default route via it. No route for the rest of the subnet.
ip route

See the VM's ARP table

  • What it shows: Every IP the VM has resolved to a MAC.
  • What to look for: Only the gateway, with a MAC starting 42:01, even after talking to other VMs.
ip neigh

Ask the metadata server a question

  • What it shows: The zone the VM runs in, straight from the metadata server.
  • What to look for: A path with the project number. Try it without the header and see the refusal.
curl -s -H "Metadata-Flavor: Google" \  http://metadata.google.internal/computeMetadata/v1/instance/zone

Test the MTU from inside the VPC

  • What it shows: Whether a full-size packet reaches kade-db without being split. 1432 bytes of data plus 28 bytes of headers is exactly 1460.
  • What to look for: 1432 works; 1433 fails with "message too long". That confirms the path MTU is 1460.
ping -c 3 -M do -s 1432 10.10.2.5ping -c 3 -M do -s 1433 10.10.2.5

Read the VPC's MTU from outside

  • What it shows: The MTU set on kade-vpc.
  • What to look for: 1460, matching what the VM reported in command 2.
gcloud compute networks describe kade-vpc --format="value(mtu)"

Spotted a mistake, or something unclear? Suggest an edit on GitHub