Cloudflare.LoadBalancer reference
LoadBalancer
Section titled “LoadBalancer”Source:
src/Cloudflare/LoadBalancer/LoadBalancer.ts
A Cloudflare Load Balancer — a zone-level DNS hostname that distributes
traffic across Pools with health-based failover,
geo/latency steering, and session affinity.
Requires the Load Balancing subscription to be enabled for the zone;
without it, creation fails with the typed LoadBalancingNotEnabledForZone
error.
LoadBalancer: Creating a Load Balancer
Section titled “LoadBalancer: Creating a Load Balancer”DNS-only (unproxied) load balancer
const lb = yield* Cloudflare.LoadBalancer.LoadBalancer("ApiLb", { zoneId: zone.zoneId, name: "api.example.com", defaultPools: [pool.poolId], fallbackPool: pool.poolId, proxied: false, ttl: 30,});Proxied load balancer with steering and affinity
const lb = yield* Cloudflare.LoadBalancer.LoadBalancer("AppLb", { zoneId: zone.zoneId, name: "app.example.com", defaultPools: [primary.poolId, secondary.poolId], fallbackPool: secondary.poolId, proxied: true, steeringPolicy: "random", sessionAffinity: "cookie",});LoadBalancer: Geo steering
Section titled “LoadBalancer: Geo steering”yield* Cloudflare.LoadBalancer.LoadBalancer("GeoLb", { zoneId: zone.zoneId, name: "geo.example.com", defaultPools: [us.poolId], fallbackPool: us.poolId, steeringPolicy: "geo", regionPools: { WEU: [eu.poolId], ENAM: [us.poolId], },});Monitor
Section titled “Monitor”Source:
src/Cloudflare/LoadBalancer/Monitor.ts
A Cloudflare Load Balancing monitor — an active health check (HTTP, HTTPS, TCP, ICMP, or SMTP probe) that Load Balancing pools reference to decide which origins are healthy.
Monitors are account-scoped and have no name field; the description
carries the physical name so lost state can be recovered. All properties
are mutable in place.
Requires the Load Balancing subscription on the account. The allowed
interval range is plan-dependent.
Monitor: Creating a Monitor
Section titled “Monitor: Creating a Monitor”HTTPS health check
const monitor = yield* Cloudflare.LoadBalancer.Monitor("ApiMonitor", { type: "https", path: "/health", expectedCodes: "2xx",});TCP port check
const tcp = yield* Cloudflare.LoadBalancer.Monitor("DbMonitor", { type: "tcp", port: 5432,});Monitor: Using with a Pool
Section titled “Monitor: Using with a Pool”const pool = yield* Cloudflare.LoadBalancer.Pool("ApiPool", { origins: [{ name: "origin-1", address: "203.0.113.10" }], monitor: monitor.monitorId,});MonitorGroup
Section titled “MonitorGroup”Source:
src/Cloudflare/LoadBalancer/MonitorGroup.ts
A Cloudflare Load Balancing monitor group — aggregates several
Monitors into one health signal that a
Pool can reference via monitorGroup (mutually
exclusive with monitor).
Monitor groups are an Enterprise-only feature; on non-entitled accounts
creation fails with the typed MonitorGroupsNotEnabled error.
MonitorGroup: Creating a Monitor Group
Section titled “MonitorGroup: Creating a Monitor Group”const group = yield* Cloudflare.LoadBalancer.MonitorGroup("ApiChecks", { members: [ { monitorId: httpsMonitor.monitorId }, { monitorId: tcpMonitor.monitorId, mustBeHealthy: false }, ],});MonitorGroup: Using with a Pool
Section titled “MonitorGroup: Using with a Pool”yield* Cloudflare.LoadBalancer.Pool("ApiPool", { origins: [{ name: "origin-1", address: "203.0.113.10" }], monitorGroup: group.monitorGroupId,});Source:
src/Cloudflare/LoadBalancer/Pool.ts
A Cloudflare Load Balancing pool — an account-scoped group of origin
servers that Load Balancers route traffic to. Pools optionally reference
a Monitor for active health checking.
Requires the Load Balancing subscription on the account; without it, pool
creation fails with the typed PoolAccessFailed error.
Pool: Creating a Pool
Section titled “Pool: Creating a Pool”Pool with one origin
const pool = yield* Cloudflare.LoadBalancer.Pool("ApiPool", { origins: [{ name: "origin-1", address: "203.0.113.10" }],});Health-checked pool
const monitor = yield* Cloudflare.LoadBalancer.Monitor("ApiMonitor", { type: "https", path: "/health", expectedCodes: "2xx",});
const pool = yield* Cloudflare.LoadBalancer.Pool("ApiPool", { origins: [ { name: "origin-1", address: "203.0.113.10", weight: 0.7 }, { name: "origin-2", address: "203.0.113.11", weight: 0.3 }, ], monitor: monitor.monitorId, minimumOrigins: 1,});Pool: Using with a Load Balancer
Section titled “Pool: Using with a Load Balancer”yield* Cloudflare.LoadBalancer.LoadBalancer("ApiLb", { zoneId: zone.zoneId, name: "api.example.com", defaultPools: [pool.poolId], fallbackPool: pool.poolId,});