Replicas and scale
This page runs web as several copies, replicas, so one copy restarting
never takes the page away and the load spreads over them. The hostname
reaches every replica of the primary in turn.
deploy.replicas is compose’s own count. Give web two.
services: web: image: nginx:1.27-alpine expose: - "80" volumes: - ./site:/usr/share/nginx/html:ro healthcheck: test: ["SHC-HTTP", ":80/"] interval: 10s timeout: 3s retries: 3 deploy: replicas: 2 x-shc-primary: true api: image: traefik/whoami:v1.10 command: ["--port", "8080", "--name", "guestbook-api"] expose: - "8080" healthcheck: test: ["SHC-HTTP", ":8080/"] interval: 10s timeout: 3s retries: 3 x-shc-path: /api x-shc-path-strip: true counter: image: redis:7-alpine command: ["redis-server", "--appendonly", "yes"] expose: - "6379" volumes: - data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 12volumes: data:$ shc update guestbook...$ shc status -s guestbook...prod guestbook prod web-r0 home01 readyprod guestbook prod web-r1 home01 ready...web-r0 and web-r1 are the two replicas. --scale changes a service’s
count at install or update without editing the file, and the deployment
keeps it for later updates.
$ shc update guestbook --scale web=3...$ shc status -s guestbook...prod guestbook prod web-r2 home01 ready...Not every service can have more than one copy. counter writes its data to
one volume, and two Redis servers writing the same files would corrupt
them. x-shc-scale.max is the most replicas a service may have, and a count
above it is refused. Cap counter at one.
services: web: image: nginx:1.27-alpine expose: - "80" volumes: - ./site:/usr/share/nginx/html:ro healthcheck: test: ["SHC-HTTP", ":80/"] interval: 10s timeout: 3s retries: 3 deploy: replicas: 2 x-shc-primary: true api: image: traefik/whoami:v1.10 command: ["--port", "8080", "--name", "guestbook-api"] expose: - "8080" healthcheck: test: ["SHC-HTTP", ":8080/"] interval: 10s timeout: 3s retries: 3 x-shc-path: /api x-shc-path-strip: true counter: image: redis:7-alpine command: ["redis-server", "--appendonly", "yes"] expose: - "6379" volumes: - data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 12 x-shc-scale: max: 1volumes: data:$ shc update guestbook...$ shc update guestbook --scale counter=2shc: [X400083PODSCL] the pods of /root/learn/guestbook cannot scale as asked: pod counter: 2 replicas is over its x-shc-scale.max of 1, the smallest among counterThe second update is refused and changes nothing. Put web back to the
file’s two.
$ shc update guestbook --scale web=2...Next: Restarting what is unhealthy.