In the current fast moving development area, continuous integration and continuous deployment (CI/CD) are important to delivering software promptly and with accuracy. A very important part of today’s deployment trend is to ensure that application updates happen continuously and smoothly without causing differences in the availability of the service, which is known as zero-downtime deployments. Kubernetes and Argo CD work together to give a more efficient method to achieve zero downtime. In this blog post, we will walk you through the process of achieving zero-downtime deployments with Argo CD and Kubernetes.
Understanding Zero-Downtime Deployments
In the case of zero-downtime deployments, programs may be upgraded or modified without affecting the service’s availability to users. So the end users will never experience service disruption even during the deployment process. Accomplishing this will require orchestration of pods which are getting updated, traffic management, and rolling back if there are any failures.
Kubernetes fundamentally advocates rolling updates, a plan to replace earlier versions of an application with new ones cautiously. Argo CD, a declarative GitOps continuous delivery tool, boosts this operation by automating and managing the lifecycle of application deployments within Kubernetes clusters, to enable smoother and better controlled updates.
Why Argo CD and Kubernetes?
- Argo CD: It is a GitOps-based tool that synchronizes the state of applications described in a Git repository with their state in a Kubernetes cluster.This synchronization improves the automation, repeatability, and predictability of Kubernetes deployments.
- Kubernetes: This container orchestration platform supports scalability and deployment management. It includes capabilities like rolling upgrades, blue-green deployments, and canary releases, which are required for zero-downtime techniques.
When combined, the declarative Argo CD idea and Kubernetes deployment approaches provide a robust platform for disruption-free deployment management.
Zero-Downtime Deployment Strategies
There are various techniques to accomplish zero-downtime deployments with Kubernetes. Let’s examine the most typically employed strategies:
1. Rolling updates
In Kubernetes, rolling updates progressively replace old pods with new ones while the service remains operational. During the update process, Kubernetes guarantees that a sufficient number of pods are accessible to service user demand.
How It Works: New pods are formed using the latest version, and old pods are terminated once the new ones are operational and ready. This guarantees that the service is continuously available during the upgrade.
Pros: Easy to configure and administer.
Cons: If not set correctly, rolling upgrades may result in brief periods of unavailability if the new pods are not healthy.
2. Canary Deployments
A canary deployment deploys new application versions to a small subset of users while the bulk utilize the old version. After stability testing, the updated version is progressively handed out to users.
How it works: A small percentage of traffic is routed to the new version, allowing testing in a production-like environment.
Pros: Controlled risk; only a small fraction of users is exposed to the new version initially.
Cons: Requires more complex configuration to manage traffic routing.
3. Blue/Green Deployments
In a blue-green deployment, a new version (green) is supplied alongside the previous version (blue), and traffic is switched to the new version as soon as it is deemed ready. This ensures that there is no downtime during the switch.
How it works: A load balancer is used to transmit traffic between the two versions while they are running concurrently. The blue version is destroyed after the green version has been confirmed.
Advantages: Complete rollback capabilities by reverting traffic to a prior version.
Cons: Double the resources are required for deployment.
4. A/B Testing
A/B testing is similar to canary deployments, but with a focus on testing different versions of the application for functionality or performance. A selection of users are offered one version, while the remainder receive another, and the results are compared.
Implementing Zero-Downtime Deployments with Argo CD and Kubernetes
Let’s look at an example of doing zero-downtime deployments using Argo CD and Kubernetes using a rolling update approach, which is one of the easiest techniques to configure.
Prerequisites :
- A Kubernetes cluster (whether local or in the cloud).
- Argo CD is installed and set up in the Kubernetes cluster.
- A Git repository with Kubernetes manifests or Helm charts.
Step 1: Create the Kubernetes Deployment Manifest.
This is an example Kubernetes deployment manifest for a simple Nginx application. It defines a deployment strategy for rolling updates, ensuring that no more than 25% of the pods are unavailable at any time during the update process.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
This configuration ensures that during an update, one extra pod will be created (maxSurge: 1), and at most, 25% of the pods will be unavailable (maxUnavailable: 25%).
Step 2: Configure the Argo CD application.
Next, create an Argo CD application that references the Git repository containing the Kubernetes manifests or Helm charts.
- Launch the Argo CD UI and build a new application.
- Configure the Git repository URL where your Kubernetes manifests are stored.
- Set up the Kubernetes cluster and namespace for the deployment.
- Configure the sync policy to automate deployments and make sure Argo CD keeps your application up to date.
Here’s an example Argo CD application manifest:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: nginx-app
spec:
destination:
namespace: default
server: https://kubernetes.default.svc
source:
repoURL: https://github.com/your-repo/nginx-app.git
path: manifests
syncPolicy:
automated:
prune: true
selfHeal: true
Step 3: Get the deployment underway
After Argo CD setup, Git repository modifications deploy the software instantly. Based on Git’s expected state and the Kubernetes cluster’s existing state, Argo CD will make any necessary adjustments.
Kubernetes will manage the rolling update using the deployment strategy.
Step 4: Monitor the deployment
Argo CD includes a simple deployment tracking interface. You may monitor pod changes live, and it will revert to the stable version if issues develop.
You can also verify the deployment’s status using Kubernetes commands:
bash
kubectl get deployment nginx-deployment
kubectl rollout status deployment/nginx-deployment
If any issues are encountered, you can manually trigger a rollback:
bash
kubectl rollout undo deployment/nginx-deployment
Step 5: Verifying Zero-Downtime Deployment
‘Curl’ or ‘hey’ can imitate service traffic to verify deployment without disruption. Zero-downtime deployment means no service disruptions.
Conclusion
To put it briefly, Argo CD’s GitOps-driven deployment automation with Kubernetes’ rolling update technique enables zero-downtime deployments. Kubernetes maintains application availability throughout updates, while Argo CD automates and synchronizes deployment to manage your cluster declaratively.
A consistent user experience requires zero-downtime deployments, which Kubernetes and Argo CD simplify. An organized update procedure, adequate monitoring, and automated deployments will allow your team to distribute changes without disrupting service.
About OpsMx
DevOps and DevSecOps teams can ship software faster with OpsMx, all while ensuring the security and 100% compliance of application releases. By building on top of open-source Argo, Spinnaker, and Flux, OpsMx provides innovative solutions and services to SHIP BETTER SOFTWARE FASTER AND SAFER.
0 Comments