Healthchecks and scaling
Deployed and supported. The fields and commands described here are stable within version v1alpha1.
A healthcheck tells the platform when a container is ready to receive traffic and when
it must be restarted. replicas, strategy and autoscale set how many instances run and
how they are replaced during an update.
Prerequisites
- A service of kind
deployment(these fields only apply to it). - No
volumeson the service forreplicas > 1orautoscale(Storage).
Steps
1. Add a probe and replicas
apiVersion: deploy.stackngo.io/v1alpha1
kind: App
metadata:
name: api
spec:
services:
api:
image: registry.gitlab.com/acme/api:1.2.0
ports: ["8080"]
healthcheck:
http: /healthz # GET /healthz on the first port
interval: 15s
timeout: 5s
retries: 3
startPeriod: 30s # gives the application 30 s to start
replicas: 2
strategy: { type: rolling, maxSurge: 1, maxUnavailable: 0 }
autoscale: { max: 6, cpu: 70 }
ingress: { port: 8080 }
sng apply api.yml
2. Follow an update
sng app patch api --image registry.gitlab.com/acme/api:1.3.0
sng app describe api
App : api
Statut : en cours
Message : api : 1/2 à jour, 2 disponibles
SERVICE KIND IMAGE PHASE URL DETAIL
api deployment registry.gitlab.com/acme/api:1.3.0 Progressing https://api-api.<tenant>.dev.stackngo.app/ RollingOut 1/2 à jour, 2 disponibles
With maxUnavailable: 0, there are always 2 instances available during the replacement.
Verification
sng app describe api returns to Statut : prête, Reconciled 2/2 prêts. During a
scale-up, the number of instances displayed exceeds replicas, up to autoscale.max.
healthcheck
Exactly one of the three tests, plus common settings:
| Field | Default | Role |
|---|---|---|
http: /path | — | GET request; healthy if the response is 2xx or 3xx |
port | first TCP port in ports | port of the http test |
tcp: 5432 | — | healthy if the TCP connection opens |
cmd: ["pg_isready"] | — | command run in the container; healthy if it exits with code 0 |
interval | 10s | delay between two tests (rounded to the second, 1 s to 1 h) |
timeout | 5s | maximum duration of a test |
retries | 3 | consecutive failures before declaring the container unhealthy (1 to 30) |
startPeriod | none | delay before the first liveness test, for slow startups |
The same probe is used twice:
- readiness: an instance that fails no longer receives traffic, without being restarted;
- liveness: after
retriesfailures, the container is restarted.startPeriodonly applies to this test.
Without a healthcheck, an instance is considered ready as soon as its container has started.
http for an API or a website, tcp for a database or a cache without an HTTP endpoint, cmd when
the image provides a tool (pg_isready, redis-cli ping). Compose healthcheck
CMD / CMD-SHELL translate to cmd.
replicas and strategy
| Field | Default | Role |
|---|---|---|
replicas | 1 | number of instances (0 to 100); 0 stops the service without deleting it |
strategy.type | rolling | rolling: gradual replacement; recreate: full stop then restart |
strategy.maxSurge | 1 | extra instances during the update (number or 25%); rolling only |
strategy.maxUnavailable | 0 | unavailable instances tolerated during the update; rolling only |
maxSurge: 0 and maxUnavailable: 0 together are rejected (the update could not
progress). A service with volumes is always in recreate.
sng app scale api 3 changes replicas without touching the rest; it is refused if the service has
an autoscale (modify autoscale.max) or a volume with a number greater than 1.
autoscale
replicas: 2
autoscale: { max: 6, cpu: 70 }
| Field | Default | Role |
|---|---|---|
max | — | maximum number of instances (1 to 100), ≥ replicas |
cpu | 80 | target utilization, in % of the CPU reservation of the size |
The minimum is replicas (1 if absent or 0). The number of instances goes up when average CPU
utilization exceeds the target, then comes back down. The target is measured against the reservation
of the size: an xs service (500m reserved) at 70% triggers at around 350m of CPU used.
With autoscale, the number of instances is no longer driven by the manifest; replicas only
serves to set the floor.
Going further
- A deployment that does not complete (instances that never become ready) ends in
Failed, reasonRolloutFailed. The usual causes: image that starts as root, probe on the wrong port or path, missing Secret.sng app logs apigives the answer. - There is no rollback command for a service: reapply the old image.
- A rolling update temporarily creates
replicas + maxSurgeinstances: with a tight plan, it is this peak that can triggerQuotaExceeded(Sizes and resources).