Application examples
Every example here is a complete application.yaml that passes sg's loader against the lab cluster from Form a cluster (members node-a, node-b, node-c). Swap in your own images, and remember images must exist on the cluster before you deploy. How to build one.
One container, smoke test
The smallest useful application. No load balancer, no exposure, just a running container with a health check.
api_version: genesis/v1
application:
name: smoke
cluster: lab
groups:
- name: box
count: 1
image: ubuntu:24.04
target: {box-0: node-a}
size: {cpu: 1, memory: 512MiB}
health: [/usr/bin/test, -d, /etc]
Container groups must always declare health. This one only proves the container booted.
A web tier behind HAProxy
Three replicas spread over three members, one load balancer. The load balancer can share a member with a replica as long as their ports differ.
api_version: genesis/v1
application:
name: site
cluster: lab
groups:
- name: web
count: 3
image: site-web-12
target: {web-0: node-a, web-1: node-b, web-2: node-c}
size: {cpu: 2, memory: 2GiB}
env:
PORT: "8080"
LOG_LEVEL: info
expose:
- port: 8080/tcp
health: [/usr/bin/curl, -fsS, http://127.0.0.1:8080/healthz]
load_balancers:
- name: edge
kind: haproxy
balances: [web]
target: {edge-0: node-a}
listen: 80/tcp
check: {type: http, path: /healthz, expect_status: 200}
Leave out check and HAProxy uses a plain TCP check. The load balancer's check is its own; it doesn't run the group's health command.
Web and PostgreSQL
The full shape: a web tier, a PostgreSQL VM on a block volume, and a load balancer.
api_version: genesis/v1
application:
name: shop
cluster: lab
groups:
- name: web
count: 2
image: shop-web-7
target: {web-0: node-a, web-1: node-b}
size: {cpu: 2, memory: 2GiB}
env:
APP_MODE: production
DATABASE_URL_HOST: 100.64.0.13
refs:
DATABASE: db-0
expose:
- port: 8080/tcp
health: [/usr/bin/curl, -fsS, http://127.0.0.1:8080/healthz]
- name: db
count: 1
type: vm
image: ubuntu:24.04
target: {db-0: node-c}
size: {cpu: 2, memory: 4GiB, root_disk: 20GiB}
volumes:
- {name: pgdata, pool: default, size: 20GiB, content_type: block, attach: [db-0], mount: /srv/pgdata}
expose:
- port: 5432/tcp
services:
- kind: postgres
version: "17"
admin_password_env: SG_PG_ADMIN_PASSWORD
load_balancers:
- name: web-edge
kind: haproxy
balances: [web]
target: {web-edge-0: node-c}
listen: 8088/tcp
check: {type: http, path: /healthz, expect_status: 200}
env and refs keys can't overlap. refs records the dependency and opens the guard path, but isn't set inside the instance in 0.1.0-dev, so the address goes in env too. See Connecting your app to the database.
A worker VM
Use type: vm when you need a real kernel: Docker inside, custom kernel modules, or stronger isolation. VM groups may skip health, but you lose the deploy-time check if you do. The full walkthrough, including building VM images and a known first-deploy gap, is Launch a VM.
api_version: genesis/v1
application:
name: jobs
cluster: lab
groups:
- name: worker
count: 2
type: vm
image: ubuntu:24.04
target: {worker-0: node-b, worker-1: node-c}
size: {cpu: 4, memory: 8GiB, root_disk: 40GiB}
health: [/usr/bin/systemctl, is-system-running, --wait]
A shared filesystem volume
Two containers on the same member sharing one filesystem volume. A volume attached to more than one instance needs security.shared: true, every instance using it must be on one member, and you approve the share explicitly.
api_version: genesis/v1
application:
name: media
cluster: lab
groups:
- name: app
count: 2
image: media-app-3
target: {app-0: node-a, app-1: node-a}
size: {cpu: 1, memory: 1GiB}
volumes:
- name: uploads
pool: default
size: 30GiB
attach: [app-0, app-1]
mount: /srv/uploads
security.shared: true
health: [/usr/bin/test, -d, /srv/uploads]
sg won't share a volume between instances on its own say-so. Without your explicit approval, plan and deploy refuse with sg:volume-share-unsafe. Approve it on every plan and deploy once you're sure two writers are fine for your app:
sg application plan --config application.yaml --force-volume-share uploads
sg application deploy --config application.yaml --force-volume-share uploads
A group parked at zero
count: 0 is valid. The group stays declared, with no instances and an empty target. Scale it up later with sg application scale.
api_version: genesis/v1
application:
name: batch
cluster: lab
groups:
- name: runner
count: 0
image: ubuntu:24.04
target: {}
size: {cpu: 2, memory: 2GiB}
health: [/usr/bin/test, -d, /etc]