Load balancers and certificates
A load balancer takes traffic on one address and spreads it across Droplets, sending each request only to Droplets that pass its health check. It can pick its Droplets by tag, so new ones join as they’re created. A certificate lets it terminate HTTPS: DigitalOcean obtains and renews one from Let’s Encrypt for domains it hosts, or you upload your own.
- https 443
- → http 8080
- certificate
- www.example.com
Get a certificate
Section titled “Get a certificate”const cert = yield* DigitalOcean.Certificate("Www", { type: "lets_encrypt", dnsNames: ["www.example.com"],});Let’s Encrypt certificates need the domain on DigitalOcean DNS, because DigitalOcean answers the challenge with DNS records. type: "custom" uploads your own certificate and key instead.
Create a load balancer
Section titled “Create a load balancer”yield* DigitalOcean.LoadBalancer("Web", { region: "nyc3", tag: "web", forwardingRules: [ { entryProtocol: "https", entryPort: 443, targetProtocol: "http", targetPort: 8080, certificateId: cert.certificateId, }, ], healthCheck: { protocol: "http", port: 8080, path: "/health" }, redirectHttpToHttps: true,});tag sends traffic to every Droplet with that tag; dropletIds names them instead. lb.ip is its public address.
Size and tune it
Section titled “Size and tune it”sizeUnit adds capacity, stickySessions keeps a client on one Droplet, and network: "INTERNAL" makes it reachable only inside its VPC.
Limits
Section titled “Limits”- A load balancer serves Droplets in its own region.
- A Let’s Encrypt certificate covers names in domains hosted on DigitalOcean DNS only.