Progressive Delivery with Argo Rollouts : Blue-Green Deployment
Tags: argo, argorollouts, progressivedelivery, deployment
Published: 2022-06-25 13:46:10

**To understand about blue-green deployment with Argo Rollouts**

Continuous Integration (CI) and Continuous Delivery (CD) have been widely adopted in modern software development enabling organizations to quickly deploy these software to customers. But doing it in the right way is equally important as in some cases unfinished code can lead to failures and customers have to face downtime.
So to solve this, progressive delivery was introduced which enables the delivery of software with the right changes to the right amount of customers at the right time. More precisely, it controls the speed at which changes are deployed for a software.

## Traditional CI/CD and Progressive Delivery

[Continuous Integration (CI)](https://aws.amazon.com/devops/continuous-integration/) is an automation process that helps in continuously integrating software development changes. It automates the building, testing, and validation of the source code. Its goal is to ultimately produce a packaged artifact that is ready to deploy.

[Continuous Delivery (CD)](https://aws.amazon.com/devops/continuous-delivery/) helps in deploying software changes to users. It needs CI which produces an artifact that can be deployed to users. Hence, [CI and CD](/ci-cd-consulting/) are often used together.

But Continuous Delivery poses many challenges, such as handling fast delivery of changes, handling high-risk failures, to ensure uptime and efficient performance of the software.
To solve the above problems of continuous delivery, progressive delivery comes into action along with different deployment strategies like blue-green deployment, canary deployment.

[Progressive Delivery](https://argoproj.github.io/argo-rollouts/concepts/#progressive-delivery) is one step ahead of Continuous Delivery. It enables delivering the software updates in a controlled manner by reducing the risks of failures. It is done by exposing the new changes of software to a smaller set of users, and then by observing and analyzing the correct behavior, it is then exposed to more users progressively. It is known to move fast but with control.

## Challenges with default “RollingUpdate” Kubernetes deployment strategy

Kubernetes comes up with default `RollingUpdate` deployment strategy which at present, have below set of limitations:

- Fewer controls over speed of the rollout
- Inability to control traffic flow to the new version
- Readiness probes are unsuitable for deeper, stress, or one-time checks
- No ability to query external metrics to verify an update
- Can halt the progression, but unable to automatically abort and rollback the update

### Argo Projects

[Argo](https://argoproj.github.io/) is a group of many open source projects which help in the fast and safe delivery of software by extending the capabilities of Kubernetes.

* [Argo Workflows](https://github.com/argoproj/argo-workflows) - Container-native Workflow Engine
* [Argo CD](https://github.com/argoproj/argo-cd) - Declarative GitOps Continuous Delivery
* [Argo Events](https://github.com/argoproj/argo-events) - Event-based Dependency Manager
* [Argo Rollouts](https://github.com/argoproj/argo-rollouts) - Progressive Delivery with support for Canary and Blue Green deployment strategies
* [Argoproj-labs](https://github.com/argoproj-labs) - separate GitHub org that is setup for community contributions related to the Argoproj ecosystem

To overcome the limitations of native Kubernetes deployment strategies, [Argo Rollouts](https://argoproj.github.io/rollouts) has been introduced and it contains below a different set of projects.

### What is Argo Rollouts?

[Argo Rollouts](https://argoproj.github.io/argo-rollouts/) is a Kubernetes controller and a set of  CRDs which provides progressive delivery features along with advanced deployments such as blue-green, canary, canary analysis. It has the potential to control and shift traffic to a newer version of software through ingress controllers and service meshes.

The below table shows comparative analysis of capabilities of the  default Kubernetes deployment strategy vs ArgoRollouts.

![Argo Rollouts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a60wgjsn008fn4rjmylg.png)

### Working of Argo Rollouts

Argo Rollout controller helps in finding and detecting the resource of a kind: Rollout in the cluster which manages the replicasets just like Kubernetes Deployment does. It creates a stable replicaset for the older version of the software and a canary replicaset for the newer version of the software.

![Working of Argo Rollouts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/paojvpdvd58rqyyvrhdi.png)

source: [Argo-Rollout-Architecture](https://argoproj.github.io/argo-rollouts/architecture/)

The `AnalysisTemplate` helps in doing the analysis of the replicasets through the `AnalysisRun` component. Together, they help to observe the working of the newly deployed version. Accordingly, it can automatically roll out to a newer version or roll back it. For this one can use any metrics tool like ***Prometheus***, ***Kubernetes jobs***, and so on.

### Lab/Hands-on of Argo Rollouts with Blue-Green Deployments

If you do not have k8s cluster readily available to do further lab then we recommend to go for [CloudYuga platform based version](https://cloudyuga.guru/hands_on_lab/blue-green-deploy-argorollout) of this blogpost. Else, you can [set up your own kind local cluster with nginx controller](https://kind.sigs.k8s.io/docs/user/ingress/#setting-up-an-ingress-controller) also deployed,and follow along to execute below commands against your kind cluster.

Clone the Argo Rollouts example GitHub repo or preferably, please fork this

```sh
git clone https://github.com/NiniiGit/argo-rollouts-example.git
```

### Installation of Argo Rollouts controller

- Create the namespace for installation of the Argo Rollouts controller

```sh
kubectl create namespace argo-rollouts
```

You will see the namespace has been created

```sh
kubectl get ns argo-rollouts
```

We will use the latest version to install the Argo Rollouts controller. 

```sh
kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml
```

You will see the **controller and other components** have been deployed. Wait for the pods to be in the `Running` state.

```sh
kubectl get all -n argo-rollouts
```

Install Argo Rollouts Kubectl plugin with `curl` for easy interaction with Rollout controller and resources.

```sh
curl -LO https://github.com/argoproj/argo-rollouts/releases/latest/download/kubectl-argo-rollouts-linux-amd64
chmod +x ./kubectl-argo-rollouts-linux-amd64
sudo mv ./kubectl-argo-rollouts-linux-amd64 /usr/local/bin/kubectl-argo-rollouts
kubectl argo rollouts version
```

Argo Rollouts comes with its own GUI as well that you can access with the below command

```sh
kubectl argo rollouts dashboard
```

and now you can access Argo Rollout console, by accessing http://localhost:3100 on your browser.
You would be presented with UI as shown below (currently it won't show you anything since we are yet to deploy any Argo Rollouts based app)

![Argo Rollouts Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5ncrnucz1hsg4xnqxed.png)

***Now, let's go ahead and deploy our first sample app using the Blue-Green Deployment strategy.***

### Blue-Green Deployment with Argo Rollouts

To experience how the [blue-green deployment](https://argoproj.github.io/argo-rollouts/features/bluegreen/) works with Argo Rollouts, we will deploy the sample app which contains Rollouts, Service, and Ingress as Kubernetes objects.\
`rollout.yaml` content:

```yaml
# This example demonstrates a Rollout using the blue-green update strategy, which contains a manual
# gate before promoting the new stack.
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollout-bluegreen
spec:
  replicas: 2
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: rollout-bluegreen
  template:
    metadata:
      labels:
        app: rollout-bluegreen
    spec:
      containers:
      - name: rollouts-demo
        image: argoproj/rollouts-demo:blue
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
  strategy:
    blueGreen: 
      # activeService specifies the service to update with the new template hash at time of promotion.
      # This field is mandatory for the blueGreen update strategy.
      activeService: rollout-bluegreen-active
      # previewService specifies the service to update with the new template hash before promotion.
      # This allows the preview stack to be reachable without serving production traffic.
      # This field is optional.
      previewService: rollout-bluegreen-preview
      # autoPromotionEnabled disables automated promotion of the new stack by pausing the rollout
      # immediately before the promotion. If omitted, the default behavior is to promote the new
      # stack as soon as the ReplicaSet are completely ready/available.
      # Rollouts can be resumed using: `kubectl argo rollouts promote ROLLOUT`
      autoPromotionEnabled: false
```

`service.yaml` content: 

```yaml
kind: Service
apiVersion: v1
metadata:
  name: rollout-bluegreen-active
spec:
  selector:
    app: rollout-bluegreen
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

---
kind: Service
apiVersion: v1
metadata:
  name: rollout-bluegreen-preview
spec:
  selector:
    app: rollout-bluegreen
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
```

`ingress.yaml` content: 

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: rollout-bluegreen
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: rollout-bluegreen-active
            port:
              number: 80
```

Now, let's create all these objects for now in the default namespace. Please execute the below commands:

```sh
kubectl apply -f argo-rollouts-example/blue-green-deployment-example/
```

You would be able to see all the objects been created in the `default` namespace by running the below commands:

```sh
kubectl get all
```

Now, you can access your sample app, by accessing http://localhost:80 on your browser.\
You would be able to see the app as shown below:

![Argo Rollouts sample app with blue-version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0odt2wxyvs71zfvt52x3.png)

Now, again visit the Argo-Rollouts console. And this time, you could see the sample deployed on the Argo Rollouts console as below:

![Blue-Green deployment on argo rollouts dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqzw3d2k0ilb6bbrgmub.png)

You can click on this `rollout-bluegreen` in the console and it will present you with its current status as below:

![Details of blue-green deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9e2j12lk4rn10gwsrcqb.png)

Going forward, either you can use this GUI or else (Preferably) use the commands shown below to continue with this demo. 

You can see the current status of this rollout by running the below command as well

```sh
kubectl argo rollouts get rollout rollout-bluegreen
```

Now, let's deploy the Green version of the app via command line

```sh
kubectl argo rollouts set image rollout-bluegreen rollouts-demo=argoproj/rollouts-demo:green
```

​​You would be able to see new i.e `green` version based set of pods of our sample app, coming up 

```sh
kubectl get pods
```

Now, after a few seconds, you would be able to see both your old set of pods (with version blue) as well as the new set of pods(with version green) available. Also on the Argo console, you would be able to see below the kind of new revision of the app with the changed image version running.

![New Version of blue-green deployement](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zmoy2ch5tb9a9a4iiik5.png)

If you visit the http://localhost:80 on your browser, you would still see only the blue version is visible rightly because we have not yet fully promoted the green version of our app
You can confirm the same now, by running the command below, which shows the new version is in paused state.

```sh
kubectl argo rollouts get rollout rollout-bluegreen
```

- Now, let us promote the green version of our app, by executing below command

```sh
kubectl argo rollouts promote rollout-bluegreen
```

Run the following command and you would see it's scaling the new i.e green version of our app completely.

```sh
kubectl argo rollouts get rollout rollout-bluegreen
```

The same can be confirmed by running the below command, which shows the old set of pods i.e old blue version of our app, terminating or already terminated.

```sh
kubectl get pods
```

If you visit the app URL on http://localhost:80 on your browser, you would see only the Green version is visible right now because we have fully promoted the green version of our app

![Argo Rollouts sample app with green-version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzups8qz65urwpowfpqx.png)

Congratulations!! you have successfully completed the blue-green deployment using Argo Rollouts.
- You can delete this entire setup i.e our sample deployed app using the below command.

```sh
kubectl delete -f argo-rollouts-example/blue-green-deployment-example/
```

## Summary

In this post, we discussed what progressive delivery is all about and its characteristics. We also learned about ArgoRollouts custom controller and how it can help to achieve the blue-green deployment, which is ultimately a form of progressive delivery.

I hope you found this post informative and engaging. For more posts like this one, do subscribe to our weekly newsletter. I’d love to hear your thoughts on this post, so start a conversation on [Twitter](https://twitter.com/NinadDesai73) or [LinkedIn](https://www.linkedin.com/in/ninad-desai/) :)
 
**What Next?**
Now we have developed an understanding of progressive delivery and created a blue-green deployment. Next would be to try the [canary deployment using Argo Rollouts](https://www.infracloud.io/blogs/progressive-delivery-argo-rollouts-canary-deployment/).
 
### References and further reading:

[Argo Rollouts](https://argoproj.github.io/rollouts/)\
[Argo Rollouts - Kubernetes Progressive Delivery Controller](https://argoproj.github.io/argo-rollouts/)

Looking for help with building your DevOps strategy or want to outsource DevOps to the experts? learn why so many startups & enterprises consider us as one of the [best DevOps consulting & services companies](/devops-consulting-services/).