RousselTMLEARNING

DevOps

End-to-end CI/CD (4/5): deployment strategies and rollback

Deploy without downtime and without risk: recreate, rolling update, blue/green, canary, feature flags, dark launch, post-deployment checks, automated analysis and rollback or roll forward.

1. The strategies #

Choosing based on risk and infrastructure.

Overview #

StrategyPrincipleDowntimeRollbackCost
Recreatestop v1 then start v2yesredeploy v1low
Rolling updatereplace instances in batchesnoprogressive (rollout undo)low
Blue/greentwo environments, traffic switchnoinstantdouble infrastructure
Canarya small share of traffic to v2, then increasednoinstant, few users affectedadvanced routing
Feature flagscode deployed but feature disablednoturn the flag offflag management

Rolling update #

# Kubernetes : jamais moins de 100 % de capacité pendant la mise à jour
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate: { maxSurge: 1, maxUnavailable: 0 }
  template:
    spec:
      containers:
        - name: api
          image: registry.example.com/shop/api:3f9c2e1
          readinessProbe:                     # le trafic n'arrive qu'aux pods prêts
            httpGet: { path: /health, port: 8080 }
            periodSeconds: 5
Good to know: Without a readiness probe, Kubernetes sends traffic to a pod that is still starting: the rolling update then produces errors.

Blue/green #

Blue/green
The new version is tested in production before receiving traffic.

Canary #

Steps of a canary
Each step is validated by metrics (error rate, latency) before the next one.
# Argo Rollouts : canary avec paliers et analyse automatique
strategy:
  canary:
    steps:
      - setWeight: 5
      - pause: { duration: 5m }
      - analysis: { templates: [{ templateName: taux-erreur }] }
      - setWeight: 20
      - pause: { duration: 10m }
      - setWeight: 50
      - pause: { duration: 15m }

2. Decoupling deployment from release #

Feature flags and dark launch.

Feature flags #

A feature flag lets you deploy inactive code and enable it later, for a percentage of users, a region or internal testers only. It is what makes trunk-based development with unfinished features possible.

if flags.is_enabled("nouveau-panier", user_id=user.id):   # OpenFeature, Unleash, LaunchDarkly, Flagsmith...
    return nouveau_panier(user)
return ancien_panier(user)
Common mistake: Every flag is debt: remove it as soon as the feature is enabled for everyone, otherwise the code accumulates dead branches that are hard to test.

Dark launch #

The new version receives a copy of real traffic (mirroring) without its responses being returned to users: performance and errors are measured without risk.

3. Verifying and rolling back #

A deployment is only finished once verified.

Automatic checks #

  1. Smoke tests right after deployment: the home page responds, login works, the health API is green.
  2. Metric analysis during ramp-up: error rate, p95 latency, saturation, compared with the previous version.
  3. Automatic decision: continue, pause or abort.
# smoke test minimal dans le pipeline
for i in $(seq 1 10); do
  curl -fsS --max-time 3 https://staging.example.com/health && exit 0
  sleep 6
done
echo "smoke test en échec" >&2 ; exit 1

Rollback or roll forward #

OptionWhen
Rollbackgo back to the previous version (same artifact, already known): the first reflex during an incident
Roll forwardquickly ship a fix: only if the pipeline is fast and the cause is understood
kubectl rollout undo deployment/api
kubectl rollout history deployment/api
helm rollback shop 41
git revert <sha> && git push      # GitOps : l'annulation passe aussi par Git

Related articles

Organizing DevOps: value streams, teams and a blameless culture

Set up a DevOps organization: value chain and value stream mapping, Team Topologies, « you build it, you run …

Git for DevOps: branches, code reviews and versions

Organize work with Git in a DevOps approach: trunk-based development or GitFlow, short-lived branches, pull r…

End-to-end CI/CD (1/5): principles and anatomy of a pipeline

Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deployment, pipeline …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!