Argo Rollouts Explained: Automating Kubernetes Deployments

Argo Rollouts Explained: Automating Kubernetes Deployments

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,

No alt text provided for this image

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.

No alt text provided for this image

If you click on this Blue-Green deployment, you will see the detailed image.

No alt text provided for this 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:

No alt text provided for this image

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
        
No alt text provided for this image

Let's check the UI with the below command

kubectl argo rollouts dashboard        
No alt text provided for this image

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.?

Also, follow me on?Twitter?to get daily updates on interesting tech articles and stories.

Abdullateef Lawal

Building AI that build, manage, & scale.

1 年

Great topic! Argo Rollouts is indeed a powerful tool for managing advanced Kubernetes deployments. ?? Canary and Blue-Green deployment strategies are essential techniques in modern application deployment, and it's fantastic to see you covering them in your newsletter. Looking forward to see more about it! ?? #Kubernetes #ArgoRollouts #DevOps

回复
Elias Coranti

Consultor de ciberseguridad en Telefónica Tech

1 年
回复

要查看或添加评论,请登录

Pavan Belagatti的更多文章

社区洞察

其他会员也浏览了