Applications overview
An application is everything one piece of software needs on your cluster: groups of containers or VMs, the volumes they mount, an optional PostgreSQL or ClickHouse service, and an optional HAProxy load balancer. You describe it in an application.yaml and sg application deploy makes it so.
The pieces
| Piece | What it is |
|---|---|
| Group | A set of identical instances: count copies of one image, each pinned to a cluster member. Containers by default, or type: vm. |
| Instance | One copy. Keyed <group>-<n> in the spec (web-0), named <app>-<group>-<n> in LXD (shop-web-0). |
| Volume | A storage volume on a member's pool, mounted into instances. filesystem or block. |
| Service | PostgreSQL or ClickHouse, installed and configured by sg inside a single-instance VM group. |
| Load balancer | One HAProxy instance that spreads a port across a group's instances. |
| Generation | A numbered record of a deploy that finished and passed every check. Rollback goes back one. |
The lifecycle
init ──► plan ──► deploy ──► status
│
├── restart (no new generation)
├── scale (edits the spec, deploys, new generation)
├── upgrade (edits the spec, deploys, new generation)
├── rollback (redeploys generation N-1 as a new generation)
└── destroy (removes sg-owned instances and volumes)
| Command | Effect | New generation? |
|---|---|---|
init | Local only. Validates and registers the spec. | no |
plan | Read-only. Prints the plan and its hash. | no |
deploy | Changes the cluster. Deploys, then checks health and exposure. | yes, when it finishes OK |
status | Read-only. State and health per instance. | no |
restart | Interrupts service. Restarts instances and checks health. | no |
scale | Edits the spec and the cluster. | yes |
upgrade | Edits the spec and the cluster. | yes |
rollback | Changes the cluster. Redeploys generation N-1. | yes (N+1) |
destroy | Deletes owned instances and their volumes. | no |
Your app ships as an LXD image
There's no build step and no cloud-init field in application.yaml. A group runs exactly the image you name, so your code, its runtime and its service manager have to be in that image already. sg passes image straight to LXD, so anything your cluster can resolve works:
| Image | Example | Good for |
|---|---|---|
| A public remote | ubuntu:24.04, images:debian/12 | Services, load balancers, smoke tests |
| An image you published | shop-web-7 | Your own applications |
The simplest way to make your own is to build it on the cluster and publish it. Images published on one member are available to all of them:
ssh root@<any-member>
lxc launch ubuntu:24.04 build-shop
lxc exec build-shop -- cloud-init status --wait # let first boot finish
lxc file push -r ./dist build-shop/opt/shop/ # your build output
lxc exec build-shop -- sh -ec '
apt-get update -q
DEBIAN_FRONTEND=noninteractive apt-get install -y -q nodejs
cp /opt/shop/dist/shop.service /etc/systemd/system/
systemctl enable shop'
lxc stop build-shop
lxc publish build-shop --alias shop-web-7
lxc delete build-shop
Give each build a new alias (shop-web-8, shop-web-9) and ship it with sg application upgrade --image. Reusing an alias for different bytes makes rollback meaningless.
How a deploy decides it worked
A deploy isn't done when the instances start. It's done when:
- every instance's
healthcommand succeeds inside it, - the load balancer (if any) is configured with the healthy backends, and
- every exposed port and the load balancer's listener answer from your workstation.
Only then is it recorded as a generation. That's why your workstation needs to be on the tailnet: exposed ports are published on each member's tailnet address.
Where to next
- Launch your first application: two web containers behind HAProxy.
- Launch a VM: the same, as virtual machines with their own disks.
- Add a database: PostgreSQL or ClickHouse on a block volume.
- Application examples: complete specs to copy.
- application.yaml reference: every field and rule.