VPCs and NAT
A VPC is a private network in one region. Droplets, Kubernetes nodes, database clusters and load balancers in it reach each other on private addresses, and traffic between them never leaves DigitalOcean’s network. Every region has a default VPC, which resources join when you don’t name one. Peering joins two VPCs, and a NAT gateway gives machines in a VPC one shared public address for outbound traffic.
nyc3region
AppVpcVPC · 10.40.0.0/20
WebDroplet
- ip
- 10.40.0.2
DbPostgres cluster
- ip
- 10.40.0.5
EgressNAT gateway · one public IP
Create a VPC
Section titled “Create a VPC”const vpc = yield* DigitalOcean.Vpc("AppVpc", { region: "nyc3", ipRange: "10.40.0.0/20" });Pass vpc.vpcId as vpcUuid on a Droplet, Kubernetes cluster, database cluster or load balancer in the same region. Without ipRange, DigitalOcean picks one that doesn’t overlap the team’s other VPCs.
Peer two VPCs
Section titled “Peer two VPCs”yield* DigitalOcean.VpcPeering("AppToData", { vpcIds: [app.vpcId, data.vpcId] });Peered VPCs, even in different regions, reach each other on private addresses.
Route outbound traffic through NAT
Section titled “Route outbound traffic through NAT”yield* DigitalOcean.NatGateway("Egress", { region: "nyc3", vpcIds: [vpc.vpcId] });Limits
Section titled “Limits”- The first VPC in a region becomes that region’s default, and a default VPC can’t be deleted. Create VPCs in regions where the team already has one, or expect the first to stay.
- A VPC’s region and IP range can’t change: changing them creates a new VPC.
- A VPC with members can’t be deleted; destroy waits until they’re gone.