In the fast-paced world of modern software development, Kubernetes has emerged as a leading container orchestration platform, empowering organizations to deploy and scale applications seamlessly. However, traditional deployment strategies often lack the finesse required to ensure smooth rollouts and minimize risks. Enter Argo Rollouts, an innovative solution that elevates Kubernetes deployments through progressive delivery techniques.
In this article, we will dive into the world of Argo Rollouts, through some practical examples of exploring how it revolutionizes the deployment process. I'll demonstrate how you can use Argo Rollouts to do Canary and Blue-Green deployments. Join us on this journey to uncover the secrets of Argo Rollouts and how it empowers developers to deliver applications with unprecedented confidence and efficiency.
Argo Rollouts
Argo Rollouts is a Kubernetes controller and toolset used for managing the progressive deployment of applications, particularly those hosted on Kubernetes clusters. It extends the functionality of Kubernetes Deployments and provides more advanced features for orchestrating the rollout of updates to applications.
Argo Rollouts Tutorial
Prerequisites:
Kubernetes cluster set up and kubectl installed and configured.
Argo CD and Argo Rollouts installed on your Kubernetes cluster.
kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml
- Argo Rollouts kubectl plugin. Install it with the following command
brew install argoproj/tap/kubectl-argo-rollouts
Let's get started with the step-by-step tutorial:
Blue-Green Deployment Strategy
Let us demonstrate how to perform a blue-green deployment using Argo Rollouts on Kubernetes. Blue-green deployment is a deployment strategy where you have two identical environments, one is the current production environment (blue), and the other is the new environment you want to deploy (green). We will use Argo Rollouts to control the traffic switching between these environments.
Step 1: Deploy the Application
Create a simple Kubernetes deployment for your application. For this tutorial, we'll use a basic Nginx deployment:
# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.10
ports:
- containerPort: 80
Apply the deployment using kubectl:
kubectl apply -f nginx-deployment.yaml
Step 2: Define the Argo Rollout Resource.
Create a Kubernetes manifest for the Argo Rollout resource:
# argo-rollout.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: nginx-rollout
spec:
replicas: 2
selector:
matchLabels:
app: nginx
strategy:
blueGreen:
activeService: nginx-active
previewService: nginx-preview
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.10
ports:
- containerPort: 80
Step 3: Create Services.
Now, create two services: one for the current production environment (blue) and the other for the new environment (green).
# nginx-active-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-active
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
# nginx-preview-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-preview
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
Apply the services:
kubectl apply -f nginx-active-service.yaml
kubectl apply -f nginx-preview-service.yaml
Step 4: Apply the Argo Rollout
kubectl apply -f argo-rollout.yaml
Step 5: Monitor the Deployment
You can monitor the status of the deployment using:
kubectl argo rollouts get rollout nginx-rollout
You should see a screen as shown below,
Step 6: Perform the Blue-Green Switch:
To switch traffic from the blue to the green environment, update the Argo Rollout resource with a new image or configuration. Argo Rollouts will handle the gradual switch.
For example, update the nginx
image in the argo-rollout.yaml
file to a new version, and then apply the update:
kubectl apply -f argo-rollout.yaml
Checking the initial rollout with the UI (use the below command)
kubectl argo rollouts dashboard -n blue-green
The below Blue-Green deployment is what you see in the UI.
If you click on this Blue-Green deployment, you will see the detailed image.
Canary Deployment Strategy
Deploying a Rollout:
First, we deploy a Rollout resource and a Kubernetes Service targeting that Rollout.
The example Rollout in this guide utilizes a canary update strategy which sends 20% of traffic to the canary, followed by a manual promotion, and finally gradual automated traffic increases for the remainder of the upgrade. This behavior is described in the following portion of the Rollout spec:
You can find the spec link here: https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/rollout.yaml
Run the following command to deploy the initial Rollout and Service:
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/rollout.yaml
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/service.yaml
To watch the rollout as it deploys, run the get rollout --watch command from plugin:
kubectl argo rollouts get rollout rollouts-demo --watch
Let's check the UI with the below command
kubectl argo rollouts dashboard
This way, you can perform the advanced deployment strategies using Argo Rollouts.
Overall, Argo Rollouts offers a more powerful and controlled approach to deploying updates to Kubernetes-based applications, allowing you to mitigate risks and ensure the stability and reliability of your production environment during the deployment process. Now you can trigger your Argo CD jobs and workflows automatically from Kubiya, a virtual assistant for DevOps professionals.
Follow me on Twitter to get daily updates on interesting tech articles and stories.