Reach Us

Integrating ArgoCD With Gitlab-CI

The customer approached us with a clear problem statement: while their GitLab-based CI/CD pipeline was serving them well, they were struggling with scaling their deployment process. They needed a solution that could automate deployments, eliminating manual intervention, while ensuring version control for traceability. Additionally, they wanted to maintain environment consistency across multiple stages and have reliable rollback options in case of failures.

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

In the era of GitOps, ArgoCD empowers teams to move fast without breaking things

ArgoCD and GitLab CI Integration

Let’s dive into the detailed steps for integrating ArgoCD with GitLab CI,

GitLab and ArgoCD streamline CI/CD workflows, enabling seamless deployments to Kubernetes clusters

Configure GitLab CI/CD Pipeline

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.

Set Up ArgoCD to Track Your GitLab Repository

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.

Trigger the GitLab CI Pipeline

Push changes to the developer branch in GitLab, and the pipeline defined in .gitlab-ci.yml will trigger:

  1. Build Stage: Executes your tests or builds the Docker image and pushes it to aws ecr repository.
  2. Deploy Stage: Pushes the configuration changes, which will be synced by ArgoCD and applied to your Kubernetes cluster automatically.

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

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from - Youtube
Vimeo
Consent to display content from - Vimeo
Google Maps
Consent to display content from - Google
Spotify
Consent to display content from - Spotify
Sound Cloud
Consent to display content from - Sound
Contact Us