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.
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.
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.
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:-
https://gitlab.com/test7474/demo.git
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:-
https://gitlab.com/test7474/k8s-manifest.git
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 git@gitlab.com: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 “sunil.p@cloudifyops.com”
– 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.
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
