DevOps Automation

 View Only

Kubernetes Blue-Green Deployments Made Easy with UrbanCode Deploy

By Osman Burucu posted Wed July 13, 2022 01:33 AM

  

This article was originaly published in 2017.07.26

Kubernetes Blue-Green Deployments Made Easy with UrbanCode Deploy

Introduction

UrbanCode Deploy (now DevOps Deploy) can simplify your blue-green and canary Kubernetes deployments by:

  • Giving you a visual representation of what is deployed where
  • Allowing you to easily change what is deployed where without the need of editing files or using a command line
  • Providing an audit trail of what was deployed when and where
  • Instituting quality gates
  • And more!

To see a working example of a blue-green Kubernetes deployment in UrbanCode Deploy, watch this video:



For step-by-step instructions on how to setup the working example shown in the video, see this article. This document explains how to set up UrbanCode Deploy to manage your Blue-Green and Canary Kubernetes deployments in general terms.

Getting Started

In a blue-green deployment, two versions of your application may be deployed at the same time while traffic is being sent to only one of the deployments. For example, version 1.0 of your application may be running as your “blue” deployment, while version 2.0 is running as your “green” deployment. A load balancer may direct all users to the blue deployment (version 1.0). Once version 2.0 has been staged and verified, the load balancer may be changed to send users to the green deployment (version 2.0). This allows for zero downtime deployments. In a simple Kubernetes blue-green deployment, you may have three YAML files. The first YAML file describes the load balancer. The load balancer has a selector which directs traffic to deployments containing either a blue label or a green label. You may also have a deployment YAML file containing the blue label, and a similar YAML file containing the green label. Before continuing, you should first be familiar with how UrbanCode Deploy manages Kubernetes deployments. Review the Enhance your Kubernetes Experience with UrbanCode Deploy article first.

Setting up the UCD Components

First, let’s create a component to represent our load balancer. In UrbanCode Deploy, go to Components and click the Create Component button. Enter a name for your component. In the Component Template field, choose the Kubernetes template. If you don’t see the Kubernetes component template, download and install it from Github. Save your component, keeping in mind that we will be creating component versions and component version artifacts (how you chose to do so is up to you). Next, create two copies of your load balancer’s YAML file. In one file, set the selector to blue. In the other file, set the selector to green. In your load balancer component, create a new version named green. Add the load balancer YAML file with the selector set to green as a component version artifact.


In your load balancer component, create a new version named blue. Add the load balancer YAML file with the selector set to blue as a component version artifact. Your load balancer component should now have two versions: blue and green.


The load balancer component is complete. Next, we will create a component that represents our application. While blue-green deployments typically use separate files for the blue and green deployments, we will use the power of UrbanCode Deploy to simplify things and use a single file for the deployment. We can then change the versions of containers running in either the blue or green deployment using UrbanCode Deploy, freeing us from manually changing multiple YAML files. If you are unfamiliar with these features, see this article. To use a single deployment YAML file, we will change the color value in a YAML file to a token. For example, a YAML file representing our blue deployment may look like this: apiVersion: extensions/v1beta1 kind: Deployment metadata: name: webpage-blue spec: replicas: 3 template: metadata: labels: color: blue spec: containers: - name: bgdemo image: amatthew99/ucdbgdemo:v1 resources: requests: cpu: 100m memory: 100Mi env: - name: GET_HOSTS_FROM value: dns ports: - containerPort: 80
Change the color value to a token like so (notice we are also changing the deployment’s name, so both deployments may be running at the same time: apiVersion: extensions/v1beta1 kind: Deployment metadata: name: webpage-@color@ spec: replicas: 3 template: metadata: labels: color: @color@ spec: containers: - name: bgdemo image: amatthew99/ucdbgdemo:v1 resources: requests: cpu: 100m memory: 100Mi env: - name: GET_HOSTS_FROM value: dns ports: - containerPort: 80
Create a component to represent our application’s YAML file. Use the Kubernetes component template when doing so. Create a component version with your YAML file as a component version artifact. You may follow the Enhance your Kubernetes Experience with UrbanCode Deploy article for more details. Add a Load Balancer tag to your load balancer component, and a Kubernetes tag to your application component. 

Setting up the UCD Application

Download and install the Kubernetes Blue-Green Deployment Application Template from Github here. For more detailed instructions, see the Enhance your Kubernetes Experience with UrbanCode Deploy article. In UrbanCode Deploy, click the Applications tab. Next, click the Create Application tab. Enter a name for your application, and, in the Application Template field, select the Kubernetes Blue-Green Deployment Application Template.


Click the Next button. Select your Kubernetes and your Load Balancer components in their respective fields. Click the Next button. The next page of the wizard shows environments to use in this application. By default, there are Blue, Green, and Load Balancer environments. Notice the Blue and Green environments include a property named Color. The Color property is set to blue in the Blue environment, and green in the Green environment.


Click the Next button. Drag an agent to each environment.

Click the Create button to finish the creation of your application.

Deploying

Click the Load Balancer environment's Request Process button to deploy your load balancer. Choose the Deploy Load Balancer from YAML process and select either the blue or green version. Click Submit to start the Deployment process. Click the Blue environment's Request Process button to deploy the blue version of your application. Choose the Deploy Application from YAML process and select the version of your application’s YAML file to use. Note: the first time you run this process, the versions of the containers will be set to whichever versions are specified in your YAML file. Going forward, you will have the ability to change container versions. Click Submit to start the Deployment process. Components have been created for each container used by your application. See the Enhance your Kubernetes Experience with UrbanCode Deploy article for information on how to import version information for these container components. Click the Green environment's Request Process button to deploy the green version of your application. Choose the Deploy Application from YAML process and select the version of your application’s YAML file to use and the desired version for the containers used in this environment. Click Submit to start the Deployment process. Once complete, you may click the Expand All link on the Application page for your application and easily gather information regarding your deployment:


In this example, we see our Load Balancer has the blue version deployed, meaning traffic is being sent to the Blue environment. In our Blue environment, version 1.0 of our container is deployed, while version 2.0 has been deployed to the Green environment. Once version 2.0 of the container is thoroughly tested and we desire to send traffic to the Green environment, simply deploy the load balancer again choosing version green. To change the version of the application yaml or containers deployed in an environment, simply deploy new versions.

Canary Deployments

A similar approach may be taken for managing canary Kubernetes deployments using UrbanCode Deploy. Review this blog post on the Kubernetes site, especially the section titled Multi-Stage Canary Deployments. Similar to the blue-green deployment example, the blog shows a cluster of HAProxy pods that are used as a load balancer. The cluster is set to send traffic to four different environments in the example (Internal, Canary (Free), Canary (Paid), Production). UrbanCode Deploy could manage the deployments as a build moves from Internal to Canary (Free) to Canary (Paid) to Production. Using the power of UrbanCode Deploy, users beneift from audit trials to show who deployed which containers and when they deployed them as well has providing governance over who is allowed to perform the deployments and to which environments.
#Kubernetes
#UrbanCodeDeploy

0 comments
12 views

Permalink