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

PieceWhat it is
GroupA set of identical instances: count copies of one image, each pinned to a cluster member. Containers by default, or type: vm.
InstanceOne copy. Keyed <group>-<n> in the spec (web-0), named <app>-<group>-<n> in LXD (shop-web-0).
VolumeA storage volume on a member's pool, mounted into instances. filesystem or block.
ServicePostgreSQL or ClickHouse, installed and configured by sg inside a single-instance VM group.
Load balancerOne HAProxy instance that spreads a port across a group's instances.
GenerationA 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)
CommandEffectNew generation?
initLocal only. Validates and registers the spec.no
planRead-only. Prints the plan and its hash.no
deployChanges the cluster. Deploys, then checks health and exposure.yes, when it finishes OK
statusRead-only. State and health per instance.no
restartInterrupts service. Restarts instances and checks health.no
scaleEdits the spec and the cluster.yes
upgradeEdits the spec and the cluster.yes
rollbackChanges the cluster. Redeploys generation N-1.yes (N+1)
destroyDeletes 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:

ImageExampleGood for
A public remoteubuntu:24.04, images:debian/12Services, load balancers, smoke tests
An image you publishedshop-web-7Your 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:

  1. every instance's health command succeeds inside it,
  2. the load balancer (if any) is configured with the healthy backends, and
  3. 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