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 deploy this software to customers quickly. But doing it correctly is essential as, in some cases, unfinished code can lead to failures, and customers have to face downtime.
So to solve this, progressive delivery got introduced which enables to deliver software with the right changes to the right amount of customers at a right time. More precisely, it controls the speed of changes in the software.
Traditional CI/CD and Progressive Delivery
Continuous Integration(CI) 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) is also an automated process that helps in deploying software changes to users. It needs CI which produces an artifact that can be deployed to users. Hence, CI and CD 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 is one step ahead of Continuous Delivery which 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 a 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 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 – Container-native Workflow Engine
- Argo CD – Declarative GitOps Continuous Delivery
- Argo Events – Event-based Dependency Manager
- Argo Rollouts – Progressive Delivery with support for Canary and Blue Green deployment strategies
- 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 has been introduced.
What is Argo Rollouts?
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, and 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 a comparative analysis of the capabilities of the default Kubernetes deployment strategy vs ArgoRollouts.
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.
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
A Kubernetes cluster should be running and this can be checked by running the kubectl get nodes
command.
- Clone the Argo Rollouts example GitHub repo or preferably, please fork this
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
kubectl create namespace argo-rollouts
You will see the namespace has been created
kubectl get ns argo-rollouts
- So we will use the latest version to install the Argo Rollouts controller.
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.
kubectl get all -n argo-rollouts
- Install Argo Rollouts Kubectl plugin with
curl
for easy interaction with Rollout controller and resources.
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
kubectl argo rollouts dashboard
and now by clicking on the available argo-rollout-app
URL on the right side under the LAB-URLs section.
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)
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 works with Argo Rollouts, we will deploy the sample app which contains Rollouts, Service, and Ingress as Kubernetes objects.
rollout.yaml
content:
# 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:
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:
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:
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:
kubectl get all
Now, you can access your sample app, by clicking on the app-port-80
URL under the LAB-URLs section.
- You would be able to see the app as shown below:
- Now, again visit the Argo-Rollouts console through the
app-rollout-app
URL. And this time, you could see the sample deployed on theArgo Rollouts console as below
- You can click on this
rollout-bluegreen
in the console and it will present you with its current status as below
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
kubectl argo rollouts get rollout rollout-bluegreen
- Now, let’s deploy the Green version of the app via command line
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
kubectl get pods
Now, after a few seconds, you would be able to see both i.e 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.
If you visit the app URL on app-port-80
, 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.
kubectl argo rollouts get rollout rollout-bluegreen
- Now, lets promote the green version of our app, by executing below command
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.
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.
kubectl get pods
If you visit the app URL on app-port-80
this time, you would see only the Green version is visible right now because we have fully promoted the green version of our app
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.
kubectl delete -f argo-rollouts-example/blue-green-deployment-example/
Conclusion
In this blog, 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.
What Next?
We have developed an understanding of progressive delivery and created a blue-green deployment. Next would be to try the next hands-on lab about canary deployment using Argo Rollouts.
You can find all the parts of this Argo Rollouts Series below: