Labs / Cloud / Guarding & joining a VPC

Lab 2 of 2 · Guarding & joining a VPC

Cloud VPN and load balancers: the office joins, the shop scales

Join an office to a VPC over a VPN, add the route it needs, then spread visitors over two servers.

Start this lab 4 steps

The idea

A VPC has more ways in than its internet gateway. Join an office to it over a site-to-site VPN, and find the route the tunnel needs on the cloud's side. Then put a load balancer in front of two servers that have no public address at all.

In through the tunnel, not back out
In through the tunnel, not back out
The route points at the gateway
The route points at the gateway
Two connections, not one
Two connections, not one
Two failed checks take a server out
Two failed checks take a server out

Steps

  1. A tunnel with no way back

    Priya runs Lumen Books, an online bookshop, in a VPC. The orders service, orders, sits in the private subnet at 10.0.1.10, port 8080, with no public address. Now the office wants it too.

    So the VPC got a VPN gateway, vgw, and the office's Router holds a site-to-site tunnel to it: IPsec, encrypted between the two routers across the internet. AWS calls it a virtual private gateway, Azure a VPN gateway.

    Both ends are set up, and the tunnel comes up by itself the moment traffic needs it.

    Ask orders for its page from clerk, a laptop in the office. Then ask vgw what went through the tunnel.

    clerk:~# curl -sS -m 3 http://10.0.1.10:8080/
    vgw:~# swanctl --list-sas
  2. Show the route table the way

    Every subnet in a VPC has a route table, and vpcRouter holds this VPC's. Read it.

    The fix in a cloud is one route: destination 192.168.10.0/24, the office, with the VPN gateway as its target. Here the target is vgw's address in the private subnet. Add it, then ask for the orders again while the lab records everything that passes between the office's public address, 198.51.100.20, and vgw.

    vpcRouter:~# ip route
    vpcRouter:~# ip route add 192.168.10.0/24 via 10.0.1.3
    clerk:~# curl -sS -m 3 http://10.0.1.10:8080/
  3. One address for two servers

    Customers visit the shop at 198.51.100.80. That's lb, a load balancer. The two shop servers behind it, shop1 and shop2, sit in the private subnet with no public address at all, so lb is the only way in.

    lb has a card in the public subnet too, 10.0.0.5, and passes each visit to one of the servers. On AWS it's an Application Load Balancer, and the servers it can pick form its target group.

    Visit the shop four times from visitor, out on the internet. The lab listens on shop1's card while you do.

    visitor:~# curl -s 'http://198.51.100.80/#[1-4]'
  4. A server fails its check

    lb asks each server for /health every second. Two failed answers in a row mark that server unhealthy, and lb stops sending it visits until two good answers bring it back. AWS checks every 30 seconds by default, and Azure's Load Balancer every 5.

    Stop shop2's web server, as a crash would. Then visit the shop four times, read lb's log about shop2, and start the web server again.

    shop2:~# killall httpd
    visitor:~# curl -s 'http://198.51.100.80/#[1-4]'
    lb:~# grep shop2 /var/log/haproxy.log
    shop2:~# httpd -p 80 -h /var/www/shop

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab