GitOps Using ArgoCD
Authored by Sunil Paswan
One of our clients was deploying their microservices to the EKS cluster using kubectl CLI. Their major problems were:
To solve these problems, the CloudifyOps team suggested the GitOps strategy using ArgoCD.
We could create a separate repository for manifest files, isolating the source code and configuration. This allowed the developers to be worry-free about managing the k8s manifest files. The developers were able to deploy their code without hands-on input from the operations teams as well.
ArgoCD helps with error detection as it validates the deployment and ensures proper feedback is given during the execution of CI/CD pipelines.
What is GitOps?
GitOps allows the entire code delivery process, including infrastructure and application definition as code and automated updates and rollbacks, to be controlled by Git.
ArgoCD is a GitOps agent that synchronizes the state of the application described in a Git repository with a deployment in the Kubernetes clusters.
The traditional way of deployment without GitOps involves the following steps:
Cons of Traditional Deployment
What is the GitOps way of Deployment on K8s
Pros of GitOps
ArgoCD Installation
kubectl create namespace argocd.
???????????kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo?
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
??OR?
Use an Ingress controller.
Demonstration on how to Implement GitOps with GitLab CICD
Create a Repository to version control your application source code.
You can create in any public Git repository. In our case, we are creating it on Gitlab. In this repository, we will push our application code.
Example:-?
Create a Second Repository to version control your Kubernetes manifest file for deployment.
Let us create the second git repository, as we did in the previous step, for our manifest files on GitLab. In this Repository we will push our application code.
Example:-
领英推荐
Create CICD pipeline
Create a CICD pipeline in your source code repository to build and push docker images. This also updates the Kubernetes manifest file with the latest docker image tag from the k8s-manifest repository, so that argoCD agent can pull the latest updates from k8s-manifest repository and apply changes on the cluster.
GitLab CICD code :-
docker-build:
??# Use the official docker image.
??image: docker:latest
??stage: build
??services:
????- name: docker:dind
??????alias: docker
??variables:
????TAG: $CI_PIPELINE_ID
????DOCKER_HOST: tcp://docker:2375
????DOCKER_TLS_CERTDIR: ""
??before_script:
????- docker login -u $DOCKER_USER -p $DOCKER_PASS
??script:
????- docker build -f Dockerfile -t su6680/techtalk:$TAG .
????- docker push su6680/techtalk:$TAG
????- apk add git
????- eval $(ssh-agent -s)
????- echo "$SSH_KEY" | tr -d '\r' | ssh-add -
????- mkdir -p ~/.ssh
????- chmod 700 ~/.ssh
????- ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts
????- git clone [email protected]:test7474/k8s-manifest.git
????- sed -i "s/su6680\/techtalk:.*/su6680\/techtalk:${TAG}/g" k8s-manifest/tech-app/deployment.yaml
????- cd k8s-manifest/tech-app/
????- git config --global user.email "[email protected]"
????- git config --global user.name "sunil"
????- git add .
????- git commit -m "Modifying image tag to build number ${TAG}"
????- git push origin main
Create the application on ArgoCD Web Console.
Follow us on our?LinkedIn Page . To know more about our services, visit our?website .
REFERENCE LINK