All posts
kubernetesengineering

Blue-Green Deployments in Kubernetes: Why Secrets and ConfigMaps Need Versions

Why unversioned Secrets and ConfigMaps break blue-green deployments in Kubernetes, and how versioning them makes rollouts and rollbacks safe.

Anshul Sao
Anshul Sao
Sep 13, 2023 · 3 min read

At Facets, we work to make application releases smooth and safe. One challenge we met was running blue-green deployments for applications. The approach promises updates without downtime, but it is not all smooth sailing, especially when an application reads Secrets and ConfigMaps.

This post explains why Secrets and ConfigMaps need versions in a blue-green rollout.

The Blue-Green Deployment Dilemma

Blue-green deployments are a common way to release new versions of applications without downtime. However, when dealing with applications that rely on Secrets or ConfigMaps, things can get tricky. Here is an example:

Imagine you have an application, "Application A," that references "Secret A." Now, you need to update "Secret A," and this change triggers a blue-green deployment for "Application A." During the transition, you have both active and preview pods of "Application A" running at the same time, some with the old data of "Secret A" and others with the new data.

Illustration of a blue team and a green team deploying software side by side

The problem is that without versioning, there's no clear way to tell which pods should use the old secret and which should use the new one. If the active pods restart, they pick up the changes from the updated "Secret A," even though they still run the old version of the application. This ambiguity can lead to serious issues in production. In the worst case, it can bring your business to a halt.

The Solution: Versioned Secrets and ConfigMaps

To avoid this and make the transition safe, version your Secrets and ConfigMaps. With versions, each iteration of a Secret or ConfigMap is a separate object, so each pod reads the configuration that belongs to its release.

Here's how it works:

  1. Versioned Secrets and ConfigMaps: Instead of updating "Secret A" in place, create a new version, "Secret A-v1." This way, old and new pods each reference the right version. Kustomize does this for you: its configMapGenerator and secretGenerator add a hash of the content to the name, so every change produces a new object and every rollout gets its own version.
  2. Rollback Safely: If something goes wrong during the deployment, rolling back becomes much safer. You switch the pods back to the previous version of the Secret or ConfigMap, which still exists unchanged.
  3. Clear Versioning Strategy: Use a clear versioning scheme to keep track of changes and make sure Secrets and ConfigMaps are updated systematically. This might be version numbers, timestamps, content hashes, or other identifiers that fit your organization.

Conclusion

Blue-green deployments offer real advantages: less downtime and less risk during application updates. However, when Secrets and ConfigMaps are not versioned, a rollout can mix old code with new configuration.

With versioned Secrets and ConfigMaps, your pods always read the right configuration, even during the transition phase of a blue-green deployment. This makes your deployments more reliable and gives you a safety net for rolling back changes.

At Facets, we learned the importance of versioning the hard way. Now we handle complex deployments with more confidence, while keeping our applications stable.

Facets runs canary releases with Argo Rollouts: see Canary releases.

Tags

#versioned-secrets-#configmaps