Networks, firewalls & load balancers
Around its servers, Better Stack Cloud offers what they need to talk to each other and to the internet: private networks that connect servers on internal addresses, firewalls that decide which traffic reaches them, reserved IPs that stay the same when the server behind them changes, and load balancers that spread traffic over servers and terminate TLS with certificates. Reserved and server IPv4 addresses bill (IPv6 is free) per Better Stack’s Cloud pricing, and load balancers bill.
- 443
- https → 3000
- firewall
- web-fw
- edgeroutes →web
Private networks
Section titled “Private networks”A Network is an IP range. Servers attached
to it get private addresses from it and reach each other without the public
internet:
const network = yield* BetterStack.Cloud.Network("private", { ipPrefix: "10.0.0.0", ipPrefixLength: 24,});const server = yield* BetterStack.Cloud.Server("web", { serverType: "AM1", image: "ubuntu-26-04", networkIds: [network.id],});Only name changes in place; the range and the zone replace the network.
Attaching a server is its networkIds prop; see
Servers.
A fixed private address
Section titled “A fixed private address”ServerPrivateIp pins a server’s
address in a network it is attached to. Leave ipAddress out to get the
next free one:
yield* BetterStack.Cloud.ServerPrivateIp("web-ip", { serverId: server.id, networkId: network.id, ipAddress: "10.0.0.5",});There is no update: changing anything replaces the address. It goes away with its server.
Firewalls
Section titled “Firewalls”A Firewall is a named set of rules you
attach to servers. Rules only allow traffic; whatever no rule matches is
dropped, in both directions. Firewalls are stateful, so replies to an
allowed connection pass.
const firewall = yield* BetterStack.Cloud.Firewall("web-fw", { rules: [ { direction: "inbound", protocol: "tcp", portFrom: 22, ipAddresses: ["0.0.0.0/0", "::/0"] }, { direction: "inbound", protocol: "tcp", portFrom: 443, ipAddresses: ["0.0.0.0/0", "::/0"], }, { direction: "outbound", protocol: "any", portFrom: 0, ipAddresses: ["0.0.0.0/0", "::/0"] }, ], serverIds: [server.id],});A firewall created through the API starts with one rule that allows all outbound traffic and no inbound rule. Add at least an SSH rule before attaching it to a server you need to reach: Services deploy over SSH. A server has at most one firewall.
Rules one at a time
Section titled “Rules one at a time”The inline rules list is the whole set: a deploy that changes the
firewall’s props makes the remote rules match it, and alchemy drift
finds rules changed outside the stack (see How deploys
behave). To add
rules one by one instead, use FirewallRule:
const app = yield* BetterStack.Cloud.Firewall("app-fw", { name: "app" });yield* BetterStack.Cloud.FirewallRule("app-ports", { firewallId: app.id, direction: "inbound", protocol: "tcp", portFrom: 8000, portTo: 8099, ipAddresses: ["10.0.0.0/8"],});Better Stack can’t update a rule, so changing one creates the new rule
first and then deletes the old one: the allowed traffic never has a gap.
Use inline rules or FirewallRule on a firewall, not both.
Reserved IPs
Section titled “Reserved IPs”A ReservedIp is a public IPv4 or IPv6
address that belongs to the team rather than a server. Assign it to a
server, and move it by changing serverId:
const ip = yield* BetterStack.Cloud.ReservedIp("ingress", { type: "ipv4", serverId: server.id,});It stays when the server is deleted. Outbound connections still leave from the server’s own address. Deleting a reserved IP releases the address for good. A reserved IPv4 address bills whether it is assigned or not, so the resource is tested against the offline mock only; see Compatibility and Better Stack’s pricing.
Load balancers
Section titled “Load balancers”A LoadBalancer spreads TCP, UDP, HTTP
and HTTPS traffic over servers. Its services listen for traffic and its
targets receive it, and both are their own resources that take the load
balancer’s id:
const lb = yield* BetterStack.Cloud.LoadBalancer("edge", { type: "LB1", networkIds: [network.id],});yield* BetterStack.Cloud.LoadBalancerService("http", { loadBalancerId: lb.id, protocol: "http", listenPort: 80, destinationPort: 3000, healthCheck: { protocol: "http", path: "/health" },});yield* BetterStack.Cloud.LoadBalancerTarget("web-target", { loadBalancerId: lb.id, type: "server", serverId: server.id, usePrivateIp: true,});A LoadBalancerService listens on
listenPort and forwards to destinationPort on the healthy targets,
checking their health on its own. A
LoadBalancerTarget is one server,
here reached over its private IP. Creating a load balancer waits until it
is running, for up to 20 minutes. Its type rescales in place.
Coming from Hetzner: a Hetzner load balancer’s services[] and targets[]
are separate resources here, and networks is networkIds.
Every server with a tag
Section titled “Every server with a tag”A target can select servers by their metadata instead of naming one:
yield* BetterStack.Cloud.LoadBalancerTarget("workers", { loadBalancerId: lb.id, type: "label_selector", selector: { role: "web" },});A target has no update: changing it replaces it.
HTTPS with a certificate
Section titled “HTTPS with a certificate”A Certificate is either uploaded
(certificateType: "uploaded", with a Redacted privateKey) or issued
and renewed by Better Stack with Let’s Encrypt ("managed", with
domainNames, no wildcards). An https service terminates TLS with it:
const certificate = yield* BetterStack.Cloud.Certificate("site", { certificateType: "managed", domainNames: ["example.com", "www.example.com"],});yield* BetterStack.Cloud.LoadBalancerService("https", { loadBalancerId: lb.id, protocol: "https", listenPort: 443, destinationPort: 3000, certificateIds: [certificate.id], redirectHttp: true,});A managed certificate starts pending and becomes issued once Let’s
Encrypt validates the domains, so point the domains at the load balancer
first; the deploy doesn’t wait for it. redirectHttp: true redirects plain
HTTP to HTTPS. Better Stack hosts no DNS, so the records live with your DNS
provider; see DNS.
Load balancers bill, so they are tested against the offline mock only; see Compatibility.
Ownership
Section titled “Ownership”Load balancers and reserved IPs this stack creates carry an alchemy entry in
their metadata, which takes one of the 10 metadata slots, so a lost create is
found again and alchemy nuke lists only Alchemy-created ones. Networks and
firewalls have no metadata: their generated name identifies them. See the
LoadBalancer and
ReservedIp references.
Where next
Section titled “Where next”- DNS: pointing your domain at a server or a website.
- Services: opening a Service’s port.
- References:
Network,Firewall,FirewallRule,ReservedIp,LoadBalancer,Certificate. - Better Stack’s docs for private networks, firewalls, reserved IPs and load balancers.