Kubernetes supports a software development lifecycle strategy called blue-green deployments, which involves running both the new and old versions of an application simultaneously in production. Read on to learn what a blue-green deployment is and why you might want to implement this tactic for your Kubernetes applications.
What Is a Blue-green Deployment?
A blue-green deployment is a software development lifecycle strategy that involves running both the new and previous versions of an application simultaneously in production. Users are gradually migrated from the older version (blue) to the newer version (green) of the application after deployment.
For fast delivery of software updates, developers needed a way to continually deploy features. Traditionally, code deployments required downtime, so they were done on specific days either weekly or monthly. This strategy slows down updates to software and doesn’t support continuous delivery.
Blue-green deployments solve this problem by running both the old and new versions of an application in production. The blue version is the old application, and the green version is the new one. Users are slowly moved over to the new green version after it has been deployed. After users are moved to the new green version, the blue version can act as a failover if code must be rolled back to the previous version due to bugs or critical errors.
Blue-green vs. Rolling Deployment with Kubernetes
In many enterprise environments, production runs on multiple servers. Instead of having multiple versions running simultaneously, a rolling deployment works with one version of an application and updates each server individually.
Suppose that you have two servers behind a load balancer and running a single production application. In a rolling deployment, a developer takes one server out of rotation, updates the application, and then puts the server back into rotation. The second server is taken out of rotation and then updated as well. Most rolling environments have three servers so that a single server can act as a failover in case there are errors in the new version environment.
Blue-green vs. Canary with Kubernetes
Canary deployments are similar to blue-green deployments, but canary deployments send specific users to the newer version of an application rather than slowly moving all users over to the new version. It’s a great strategy for testing a new application with users interested in beta testing or silently testing new features with new users for feedback.
Usually, canary deployments are used on a small subset of users and the original version still runs for a majority of users. Because only a small subset of users are directed to the new version, the infrastructure is less costly and does not need to be too advanced to support a small number of users.
Advantages of a Blue-green Deployment
In any continuous delivery environment, blue-green deployments offer several benefits. Blue-green deployments speed up delivery of application feature updates. Developers no longer need to wait for a window to deploy new code, which can delay deployments for potentially months.
Of the three deployment types, blue-green deployments are safer than the others. Both versions of the application run simultaneously, so developers can roll back changes without much effort. Users won’t experience downtime or lose productivity during deployments or rollbacks if they’re necessary.
Disadvantages of Blue-green Deployment
The biggest disadvantage of blue-green deployments is the expense. Companies must have the IT budget to pay for dual environments that can host both the blue and the green versions of an application. Organizations also pay for the staff overhead to maintain and monitor both environments.
Another hurdle for organizations is synchronization of databases. Database changes aren’t as easily rolled back, so updates to tables and database schema must be done carefully, especially if both green and blue environments use the same database. Both environments must be carefully tested before being deployed to production databases.
When to Use a Blue-green Deployment with Kubernetes
Continuous delivery and Kubernetes go hand in hand. Developers can automatically deploy applications using orchestration tools like Kubernetes. Kubernetes can be used to orchestrate both the blue and the green environments, and developers can simply deploy code and let Kubernetes manage promoting code from a staging environment to production.
Containerized environments are perfect for blue-green deployments for their ability to quickly destroy and rebuild application pods so that they can run either blue or green versions. If a container application causes errors, developers can more easily roll back changes to the blue version.