How to setup ArgoCD:
ArgoCD is the deployment tool for Kubernetes. We can store our
configuration file in github and if we update any file. AgroCD will
automatically deployed it.
Pre-requisite:
We need to have running EKS cluster. EC2 instance with kubectl,
Terraform, AWS CLI installed.
Install AWS CLI and Configure
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
Okay now after installing the AWS CLI, let's configure the AWS CLI so that it can
authenticate and communicate with the AWS environment.
aws configure
Install and Setup Kubectl
Moving forward now we need to set up the kubectl also onto the EC2 instance.
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s
https://storage.googleapis.com/kubernetes-
release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version
Follow below steps to install terraform on AmazonLinux.
sudo yum install -y yum-utils shadow-utils
sudo yum-config-manager --add-repo
https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Creating an Amazon EKS cluster using terraform
Code available in https://github.com/ksnithya/blue-green.git
git clone https://github.com/ksnithya/blue-green.git
cd blue-green
terraform init
terraform plan
terraform apply
aws eks --region ap-south-1 update-kubeconfig --name eks_cluster_demo
Steps:
1. First we create namespace to install argocd.
kubectl create namespace argocd
2. Let's run the following command to install agrocd.
kubectl apply -n argocd -f
https://raw.githubusercontent.com/argoproj/argo-
cd/stable/manifests/install.yaml
3. Let see what are the resources created.
kubectl -n argocd get all
4. We see the what service mapped to agrocd server.
kubectl get svc -n argocd
5. Agrocd-server service is mapping to “ClusterIP”. We need to change it to “LoadBalancer” or
“NodePort” to access the agrocd UI from outside world.
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type":
"LoadBalancer"}}'
6. Now service will be changed to “LoadBalancer”
[ec2-user@ip-172-31-42-60 helm]$ kubectl get svc argocd-server -n argocd
NAME TYPE CLUSTER-IP EXTERNAL-IP
PORT(S) AGE
argocd-server LoadBalancer 172.20.26.38 ac56ae5e4ee004f588e14968903ea1b2-
1457899865.ap-south-1.elb.amazonaws.com 80:31894/TCP,443:31830/TCP 9m11s
Now we can login to argocd using Loadbalancer.
http:// ac56ae5e4ee004f588e14968903ea1b2-1457899865.ap-south-1.elb.amazonaws.com
7. Default username is “admin” and password we can get it from secret.
[ec2-user@ip-172-31-42-60 helm]$ kubectl get secret -n argocd
NAME TYPE DATA AGE
argocd-initial-admin-secret Opaque 1 20m
argocd-notifications-secret Opaque 0 21m
argocd-secret Opaque 5 21m
[ec2-user@ip-172-31-42-60 helm]$
[ec2-user@ip-172-31-42-60 helm]$ kubectl get secret -n argocd argocd-initial-admin-secret -
o yaml
apiVersion: v1
data:
password: Vld1UG5yQ21hT2FqczJtVQ==
kind: Secret
metadata:
creationTimestamp: "2023-12-28T11:30:26Z"
name: argocd-initial-admin-secret
namespace: argocd
resourceVersion: "3173"
uid: cb246043-44d6-499e-bfa0-7a80857ea2aa
type: Opaque
[ec2-user@ip-172-31-42-60 helm]$
[ec2-user@ip-172-31-42-60 helm]$ echo "Vld1UG5yQ21hT2FqczJtVQ=="|base64 -d
VWuPnrCmaOajs2mU[ec2-user@ip-172-31-42-60 helm]$
We can use this password to login. After login it is recommended to change the password.
http:// ac56ae5e4ee004f588e14968903ea1b2-1457899865.ap-south-1.elb.amazonaws.com
Click on “Save password”.
8. Now we install argocd CLI.
sudo curl -sSL -o /usr/local/bin/argocd
https://github.com/argoproj/argo-cd/releases/latest/download/argocd-
linux-amd64
sudo chmod +x /usr/local/bin/argocd
9. Now we login to argocd CLI.
argocd login $ARGOCD_SERVER --username admin --password $ARGO_PWD –
insecure
10. Now we create deployment app using argocd UI.
In the ArgoCD web interface and click on Settings -> Repositories
On the next page click on Connect Repo and fill input the necessary details.
Under “Repository URL” we can give the github link where our code exist.
Repo: https://github.com/ksnithya/blue-green.git
Fill out just these three places and leave the rest options. Head up and click on Connect
Now we have connected our GitHub repository with ArgoCD. Let's go build our application.
11. Click on the Applications page and click on create new app
Fill the details as above.
Fill the source details. Code is under blue directory so we need to give the directory path
where our code exist.
Select the cluster URL and Namespace.Now click on create. It will create the app.
We can see our app deployed in our cluster server.
We can access the app using Loadbalancer URL.
http://aecebf280760445fdae885d20b301fad-1480116829.ap-south-
1.elb.amazonaws.com:5001
12. Now we can update our python app and create new image and push to dockerhub. Update
that image details in our deploy.yml file in our repo and click on sync in app.
It will sync and redeploy it.
Now app is deployed with new image.