Form a cluster

Applications deploy onto a cluster, not a single machine. A cluster is three or more sg machines joined into one native LXD cluster, so instances can be placed on any member and share one image store.

Before you start

  • Three or more machines created by sg in this directory. They share the ledger at .sg/state.db; a machine made from another directory doesn't count.
  • All of them on the same LXD channel (the default 5.21/stable is fine).
  • Each machine's tailnet IPv4 address. tailscale status on your workstation lists them, or run tailscale ip -4 on the host.

1. Write cluster.yaml

api_version: genesis/v1
cluster:
  name: lab
  members:                          # members[0] bootstraps the cluster
    - name: node-a                  # a machine registered in this ledger
      core_address: "100.64.0.11:8444"
    - name: node-b
      core_address: "100.64.0.12:8444"
    - name: node-c
      core_address: "100.64.0.13:8444"

core_address is the member's tailnet address and LXD API port. It must:

  • carry an explicit port, never 8443 and never a wildcard;
  • be unique across members;
  • match the address the member actually has and the port its LXD is bound to. sg checks this against what it observes, never DNS.

Put cluster.yaml in the same directory as the machine specs.

2. Create it

There's no init or plan for clusters: create shows its plan and asks once.

sg cluster create --config cluster.yaml
Form cluster lab over 3 member(s)? Membership grants shared root-level trust. [y/N]:

Before asking, sg checks every member: registered, with install.lxd, firewall.guard and verify.isolation applied; matching LXD versions; compatible storage pools and bridges; and a working control path from each joiner to the bootstrap member. Any mismatch is a refusal that names the member.

The run applies four kinds of change:

ChangeDoes
cluster.bootstrapTurns on clustering on members[0]
cluster.join.<member>Joins each other member with a one-time token that never touches disk, a plan or the ledger
cluster.guard.peersExtends every member's firewall guard so members can reach each other
cluster.verifyChecks exact membership and the guard on each member, and boots a throwaway VM per member to re-prove isolation

When it finishes, the cluster is registered in the ledger, and application.yaml files can name it.

Rules that protect you

  • Editing cluster.yaml never releases a member. Teardown follows the recorded roster, not the file.
  • A member refuses a direct sg machine destroy. You'd be pulling a node out from under a running cluster.

Taking a cluster apart

sg cluster destroy --config cluster.yaml --with-machines

Today this is the only cluster teardown that completes. Plain sg cluster destroy always refuses with sg:cluster-teardown-unsupported, because the pinned LXD version can't remove the final member natively.

With --with-machines, every recorded member gets a full machine teardown, the same as sg machine destroy. You see every member's plan, then answer one question. That deletes every instance and pool on every member.

Next

Launch your first application on your new cluster.