Skip to content

CI/CD pipeline for Microservices using Azure DevOps and ArgoCD to deploy microservices. The pipeline handles building and pushing Docker images to Azure Container Registry and deploying them to a Kubernetes cluster managed by ArgoCD.

License

Notifications You must be signed in to change notification settings

vsingh55/AzureDevOps-CI-CD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure DevOps CI/CD

This project demonstrates how to set up a CI/CD pipeline using Azure DevOps and ArgoCD to deploy microservices. The pipeline handles building and pushing Docker images to Azure Container Registry and deploying them to a Kubernetes cluster managed by ArgoCD. This ensures a streamlined, automated, and scalable deployment process, providing continuous integration and continuous delivery capabilities.

Table of Contents

diagram-export-9-6-2024-2_17_46-am

Installation

Prerequisites

Steps

  1. Sign up for an Azure account.

    • Visit the Azure website and sign up for an account if you don’t already have one.
  2. Sign in to the Azure portal and Azure DevOps services.

Setup

Provision Azure Resources

  • Approach 1: Provision resources using Terraform
  • Approach 2: Manually provision resources on the Azure portal.
    • Create a Linux VM, Azure Container Registry (ACR), and Azure Kubernetes Cluster (AKS).

Azure DevOps Project

  1. Create a new project in Azure DevOps.
    • Go to Azure DevOps and create a new project.
  2. Go to the Git section and export the repository.
  3. Obtain 2 personal access tokens (one for Azure agent, one for ArgoCD).
    • These tokens will be used for authentication in subsequent steps.

Continuous Integration

Agent Pool Setup

  1. Add the created VM to the agent pool.
    • Go to user settings in Azure DevOps, visit settings in the left corner, and look for agent pools.
  2. Delete any existing agents.
  3. Run the necessary commands on the VM to set up the agent pool.
    • Use the following commands:
      wget https://vstsagentpackage.azureedge.net/agent/3.239.1/vsts-agent-linux-x64-3.239.1.tar.gz
      sudo apt update
      sudo apt install docker.io  
      mkdir myagent && cd myagent
      tar zxvf vsts-agent-linux-x64-3.239.1.tar.gz
      ./config.sh
    • Provide the server URL (https://dev.azure.com/{your-organization}) and the personal access token when prompted.
    • Start the agent: ./run.sh.
  4. Ensure the agent is running and listening for jobs and is online on the DevOps portal.

Pipeline Setup

  1. Visit the pipeline section in Azure DevOps.
  2. Create pipelines for each microservice (voting-app, result-app, worker-app).
  3. Select Azure Repo Git and Docker (build and push image to Azure Container Registry option).
  4. Use the provided .yml files from the repository for each pipeline.

Continuous Delivery

Create a Kubernetes cluster

  • If Terraform is used, it will be automatically created. Otherwise, manually create it on the portal.
  • Note: For free tier accounts, you might encounter usage quota issues. Provision the cluster in a different region and set node config to default node=1 and max node=2.
  • Enable public IP and set max pods per node to min = 30.

ArgoCD Setup

  1. Install ArgoCD on the Kubernetes cluster.

    • Run:
      kubectl create namespace argocd
      kubectl apply -n argocd -f https://github.com/raw/argoproj/argo-cd/stable/manifests/install.yaml
      kubectl get pods -n argocd
    • Ensure all pods are running.
  2. Configure ArgoCD.

    • Retrieve the initial admin password:
      kubectl get secrets -n argocd
      kubectl edit secret argocd-initial-admin-secret -n argocd
      echo <password> | base64 --decode
    • Access the ArgoCD UI:
      kubectl get svc -n argocd
      kubectl edit svc argocd-server -n argocd
      
    • Change ClusterIP to NodePort
      kubectl get svc -n argocd
      kubectl get nodes -o wide
      
    • Access ArgoCD UI in the browser using node-external_ip:nodeport.
  3. Connect ArgoCD to Azure Git Repo.

    • In ArgoCD UI, go to settings and add the Git repository using the URL format:
      https://<personal_access_token>@dev.azure.com/<organization_name>/<project_name>/_git/<project_name>
    • Create an application in ArgoCD with the following details:
      • Name: voteapp
      • Project: default
      • Sync policy: automatic
      • Repository URL, path, and cluster URL will be auto-populated.
      • Namespace: default
  4. Update Kubernetes manifests using scripts.

    • Create a folder for scripts in the Azure repo and write a script to update the manifests with the new image name from the ACR.
    • Add an update stage in your pipelines to include this script.
    • Ensure AKS can pull images from ACR by creating a secret:
      kubectl create secret docker-registry <secret-name> \
      --namespace <namespace> \
      --docker-server=<container-registry-name>.azurecr.io \
      --docker-username=<service-principal-ID> \
      --docker-password=<service-principal-password>

Blog

  • For detailed instructions and documentation, visit the blog.

License

  • This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgement

  • Thanks to Azure DevOps & ArgoCD for providing the platform and tools to build this CI/CD pipeline.

Feel free to open issues or pull requests if you have any questions or suggestions!

About

CI/CD pipeline for Microservices using Azure DevOps and ArgoCD to deploy microservices. The pipeline handles building and pushing Docker images to Azure Container Registry and deploying them to a Kubernetes cluster managed by ArgoCD.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published