How to Run a Canary Deploy With GitLab CI/CD
A canary sends a small share of traffic to the new version, and a separate manual job promotes it to the full fleet.
Deploy the canary at a low weight, watch it, then promote with a manual promote job that scales the new version to 100% and retires the old one.
Steps
- Deploy the new version at a small weight (e.g. 10%).
- Observe error rate and latency on the canary.
- Add a manual
promotejob to shift to 100%. - Add a manual
abortjob to roll the weight back to 0%.
.gitlab-ci.yml
.gitlab-ci.yml
canary:
stage: deploy
script:
- ./set-weight.sh --version "$CI_COMMIT_SHORT_SHA" --weight 10
environment:
name: production
promote:
stage: deploy
needs: [canary]
when: manual
script:
- ./set-weight.sh --version "$CI_COMMIT_SHORT_SHA" --weight 100
environment:
name: productionGotchas
- Give the canary enough traffic and time to surface real errors before promoting.
- Automate the abort path so a bad canary does not depend on someone watching a dashboard.
Related guides
How to Run a Blue-Green Deploy With GitLab CI/CDRun a blue-green deploy in GitLab CI/CD by releasing to the idle color, then switching the live pointer in a…
How to Set Up Review Apps Per Merge Request With GitLab CI/CDSpin up a temporary review app per merge request in GitLab CI/CD with a dynamic environment and on_stop job t…