The customer approached us with a clear challenge: while their GitLab-based CI/CD pipeline was effective, they struggled with scaling deployments efficiently. They needed a fully automated deployment solution to eliminate manual intervention while ensuring version control for traceability. Additionally, maintaining environment consistency across multiple stages and implementing reliable rollback options in case of failures were critical requirements. Leveraging our Cloud Consulting Services, we designed a scalable, automated deployment framework that enhances efficiency, reliability, and resilience, enabling seamless software delivery across cloud environments.
After understanding their requirements, we at CloudifyOps proposed a tailored solution by integrating ArgoCD into their existing GitLab CI/CD pipeline. This integration would streamline their deployment process, improve traceability, and provide the scalability and reliability they were seeking.
In the era of GitOps, ArgoCD empowers teams to move fast without breaking things
In this blog, we’ll explore how to integrate ArgoCD with GitLab CI, allowing continuous delivery to Kubernetes, triggered by changes to your Git repository. This setup brings the best of both CI and GitOps, reducing deployment complexity, increasing visibility, and empowering your development teams to move faster.
With ArgoCD and GitLab CI together, visibility into deployments is no longer a luxury; it’s a fundamental practice of modern DevOps
Let’s dive into the detailed steps for integrating ArgoCD with GitLab CI,
Set up your GitLab CI pipeline to trigger the deployments via ArgoCD.
Create .gitlab-ci.yaml in the root of your git repository
stages:
- build
- deploy
variables:
# Set your Docker image name to nginx
IMAGE_NAME: nginx
IMAGE_TAG: latest
# Define your AWS ECR repository URL
ECR_REPOSITORY: your-account-id.dkr.ecr.your-region.amazonaws.com/nginx
# Define your Kubernetes context for EKS
KUBE_CONTEXT: dev-eks-cluster
AWS_ACCESS_KEY_ID: $DEV_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $DEV_AWS_SECRET_ACCESS_KEY
build:
stage: build
Script:
- apk add --no-cache aws-cli
- aws configure set aws_access_key_id ${AWS_ACCESS_KEY_ID} --profile default
- aws configure set aws_secret_access_key ${AWS_SECRET_ACCESS_KEY} --profile default
- echo "Building the Nginx Docker image"
- docker build -t $IMAGE_NAME:$IMAGE_TAG .
- echo "Logging in to AWS ECR..."
- aws ecr get-login-password --region your-region | docker login --username AWS --password-stdin $ECR_REPOSITORY
- echo "Tagging Docker image for ECR..."
- docker tag $IMAGE_NAME:$IMAGE_TAG $ECR_REPOSITORY:$IMAGE_TAG
- echo "Pushing Docker image to ECR..."
- docker push $ECR_REPOSITORY:$IMAGE_TAG
only:
- dev
deploy:
stage: deploy
Script:
- apk add --no-cache aws-cli
- aws configure set aws_access_key_id ${AWS_ACCESS_KEY_ID} --profile default
- aws configure set aws_secret_access_key ${AWS_SECRET_ACCESS_KEY} --profile default
- echo "Deploying to Kubernetes"
- echo "Setting Kubernetes context to $KUBE_CONTEXT"
- kubectl config use-context $KUBE_CONTEXT # Switch to the specified Kubernetes context
- kubectl apply -f k8s/deployment.yaml
only:
- dev
The above pipeline includes a build stage and a deploy stage that will trigger the Kubernetes deployment after a successful build.
Now, configure ArgoCD to monitor the Git repository for changes and automatically deploy the updates.
Create the ArgoCD Application YAML:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: gitlab-app
namespace: argocd
spec:
project: default
source:
repoURL: 'https://gitlab.com/repo-name.git'
path: 'k8s'
targetRevision: developer
destination:
server: 'https://kubernetes.default.svc'
namespace: argocd
syncPolicy:
automated:
prune: true
selfHeal: true
Now, apply the above file using the command below,
Kubectl apply -f gitlab-argo.yaml -nargocd
This configuration tells ArgoCD to track changes in the GitLab repository and deploy updates into the Kubernetes cluster.
Push changes to the developer branch in GitLab, and the pipeline defined in .gitlab-ci.yml will trigger:
You can monitor the deployment progress in the ArgoCD UI, which provides visibility into your application’s state.
If your organization wants to embrace GitOps or enhance your existing CI/CD practices, CloudifyOps is here to help. Let’s work together to unlock the full potential of your development and deployment workflows.
Combine GitLab CI’s flexibility with ArgoCD’s power, and your Kubernetes workflows will never be the same
Â
CloudifyOps Pvt Ltd, Ground Floor, Block C, DSR Techno Cube, Survey No.68, Varthur Rd, Thubarahalli, Bengaluru, Karnataka 560066
CloudifyOps Pvt Ltd, Cove Offices OMR, 10th Floor, Prince Infocity 1, Old Mahabalipuram Road, 50,1st Street, Kandhanchavadi, Perungudi, Chennai, Tamil Nadu - 600096
CloudifyOps Inc.,
200, Continental Dr Suite 401,
Newark, Delaware 19713,
United States of America
Copyright 2024 CloudifyOps. All Rights Reserved