Scale
Graft provides a native scale command to adjust the number of running replicas for any service. Scaling persists through deploys.
graft scale <service> <n>
Section titled “graft scale <service> <n>”Scale a service to N replicas via Traefik load balancing.
graft scale backend 3 # 3 instances of backendgraft scale backend 1 # remove replicas, back to singlegraft env staging scale backend 2 # scale in staging envWhat it does:
- Creates
<service>-scale-2,<service>-scale-3, etc. in the remote compose file. - Each replica gets the Traefik loadbalancer label so traffic is distributed automatically.
- Starts the new replica containers alongside existing ones.
Scaling back to 1 removes the extra replicas from the compose file and stops the additional containers.
Load Balancing with Traefik
Section titled “Load Balancing with Traefik”When scaling a service behind Traefik, all replicas are automatically added to the load balancer pool. No label changes are required — Graft handles this for you.
services: backend: build: ./backend labels: - "traefik.enable=true" - "traefik.http.routers.backend.rule=Host(`api.example.com`)" - "traefik.http.services.backend.loadbalancer.server.port=8080" networks: - graft-public# Scale to 3 replicas — Traefik distributes traffic across all threegraft scale backend 3Example Workflow
Section titled “Example Workflow”# Scale up before a traffic spikegraft scale backend 3
# Check that all instances are runninggraft ps
# Deploy an update — replicas persistgraft sync backend
# Scale back downgraft scale backend 1