Support for manual and instant rollback on blue/green
Feature Request
- Support for manual rollback
- Keep old version running for give period of time
Description
I just started using flagger to handle blue/green deployments using helm in k8s, but I was wondering, if there is a way to to keep the blue version running for a given period after the rollout, because there is a need to provide a mechanism for manual rollbacks to developers. I notice after running the conformance tests, it triggers automatically the rollout and scales down the old version. But the scenario I need to cover is: Scale the new version and redirect the traffic, while keeping the old version running for some time before scaling down. The rollback could be done by adding annotations to the deployment.
Related to #453
@dpolicastro thank you for opening this. Your description sounds plausible to me.
Before actually implementing this, we'd better discuss the design.
As for keeping old version running for given period of time, it is quite simply and just done by adding something like oldVersionTerminationGracePeriodSeconds field in canary CRD.
But adding manual rollback functionality would be a little bit tricky. Should we add rollBack: boolean field and allow yours to directly patch the canary resource on this field?
@stefanprodan any thoughts on this?
Both things are achievable with webhooks. The confirm-promotion keeps the old version running and rollback allows users to manually rollback.
Both things are achievable with webhooks. The
confirm-promotionkeeps the old version running androllbackallows users to manually rollback.
Does this mean that the new version won't get promoted? Then it's hardly a solution. Ideally, we'd want the traffic on the new version but have the ability to instantly switch it back.
I understand this is a big feature, but without it, it's practically impossible to run mission-critical services with Flagger.
Is this still something that's being looked into? I'm looking at flagger to improve our deployment processes, and I like a lot of what I see, but the lack of instant rollbacks is definitely a big point against adopting it.
@mathetake It doesn't appear that the terminationGracePeriodSeconds field will accomplish this either, from https://github.com/fluxcd/flagger/blob/main/docs/gitbook/tutorials/zero-downtime-deployments.md#graceful-shutdown
Before a pod gets terminated, Kubernetes sends a SIGTERM signal to every container and waits for period of time (30s by default) for all containers to exit gracefully. If your app doesn't handle the SIGTERM signal or if it doesn't exit within the grace period, Kubernetes will kill the container and any inflight requests that your app is processing will fail.
So the containers will still receive the SIGTERM signal, causing the service to begin terminating, this just gives a grace period before the containers get killed if they haven't shut down gracefully in response to that signal. I suppose it could be used in a hacky way to achieve the goal of keeping the services alive for the grace period by ignoring SIGTERM, but that doesn't sit particularly well with me.
I haven't yet tested this, so let me know if this works, but I think I have devised a way to make instant rollback work with Flagger. It involves using webhooks and two Canary definitions, where the primary deployment of one is the canary deployment of the other.

To do this, create two Canary definitions; one we'll refer to as release candidate and the other we'll call production.
Release Candidate Canary
The release candidate definition is responsible for triggering the promotion of your production canary.
- Create the release candidate Canary definition and configure the confirm-rollout webhook to trigger the promotion of your production canary.
- Ensure the webhook returns a non-200 HTTP code until your production canary has been promoted.
- Once the production canary has been promoted, the release candidate will get promoted to primary, triggering the production canary rollout.
Production Canary
The production definition is responsible for serving your application externally and its canary is the release candidate primary.
- Create the production Canary definition and configure the confirm-rollout webhook to prevent promoting its canary to primary unless the release candidate triggers a promotion.
- Configure the production Canary
targetRefto point to the release candidate primary. - Configure a rollback webhook to allow you to manually trigger a rollback.
And that should be it!
This should keep around the last good version of your app that you can instantly roll back to.