LoadBalancer
Source:
src/Hetzner/LoadBalancer.ts
A Hetzner Cloud Load Balancer. Create it in a Location (nbg1 by
default) with type lb11, then sync algorithm, listeners, targets,
private Networks, delete protection, and labels.
Location and network zone are immutable (changing either replaces the
Load Balancer). Type can grow in place. Server targets take a
Hetzner.Server; HTTPS listeners take Hetzner.Certificates.
Creating a Load Balancer
Section titled “Creating a Load Balancer”Basic TCP Load Balancer
const lb = yield* Hetzner.LoadBalancer("edge", { location: "nbg1", loadBalancerType: "lb11", services: [ { protocol: "tcp", listenPort: 80, destinationPort: 80 }, ],});With a Server target
const server = yield* Hetzner.Server("web", { serverType: "cx23", image: "ubuntu-24.04", location: "nbg1",});const lb = yield* Hetzner.LoadBalancer("edge", { algorithm: "round_robin", services: [ { protocol: "tcp", listenPort: 80, destinationPort: 80 }, ], targets: [{ type: "server", server }],});HTTPS with a Certificate
Section titled “HTTPS with a Certificate”const cert = yield* Hetzner.Certificate("web", { certificate: pem, privateKey: key,});const lb = yield* Hetzner.LoadBalancer("edge", { services: [ { protocol: "https", listenPort: 443, destinationPort: 80, http: { certificates: [cert], redirectHttp: true }, }, ],});Private Networks
Section titled “Private Networks”const network = yield* Hetzner.Network("vpc", { ipRange: "10.0.0.0/16", subnets: [ { type: "cloud", ipRange: "10.0.1.0/24", networkZone: "eu-central" }, ],});const lb = yield* Hetzner.LoadBalancer("edge", { networks: [network], services: [ { protocol: "tcp", listenPort: 80, destinationPort: 80 }, ],});