Add and Manage Multiple GKE Clusters with ArgoCD

I am a DevOps engineer with over 1.5 years of experience. I am passionate about writing for both human beings and virtual machines
ArgoCD is a powerful Continuous Delivery (CD) tool that simplifies the deployment and management of applications in Kubernetes clusters. It allows users to define the desired state of their applications in Git repositories and automatically ensures that the clusters match that state. One of the key features of ArgoCD is its ability to manage applications across multiple Kubernetes clusters from a single ArgoCD instance. In this blog, we will explore the step-by-step process of adding multiple Kubernetes clusters to ArgoCD.
Prerequisites
Before proceeding, make sure you have the following prerequisites in place
A running ArgoCD server
Kubernetes clusters that you want to connect to ArgoCD
How to setup ArgoCD and connect to private github repo
In my previous blog I have covered this topic for setup ArgoCD and connect to private github repo you will also get their sample code to perform this blogs tutorial that is important please do checkout before this blog
Part-1: Setting Up CI/CD using GitHub Actions, SonarCloud, and ArgoCD on Google Kubernetes Engine
GKE Clusters Set-Up
- Create 2 gke clusters ( you can create multiple clusters as per your comfort )
gcloud container clusters create dev --num-nodes=2 --zone=us-central1-a
gcloud container clusters create prod --num-nodes=1 --zone=us-central1-a
Note: Make sure argoCD server should be installed on dev cluster
- Get config entry in Cloud shell for dev cluster
gcloud container clusters get-credentials dev --zone=us-central1-a
gcloud container clusters get-credentials prod --zone=us-central1-a
dev cluster is the one where we will install argoCD CLI
Install ArgoCD CLI
- The ArgoCD CLI (argocd) is a command-line tool that allows you to interact with the ArgoCD server. If you haven't already installed it, download the CLI from the official ArgoCD releases page and ensure it is in your system's PATH.
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
- Connect to ArgoCD Server To interact with the ArgoCD server, use the
argocd logincommand. Replace<ARGOCD_SERVER_ADDRESS>,<USERNAME>, and<PASSWORD>(or<TOKEN>) with the appropriate values for your ArgoCD instance.
<ARGOCD_SERVER_ADDRESS> don't include https or http just keep IP only
argocd login <ARGOCD_SERVER_ADDRESS> --username <USERNAME> --password <PASSWORD>
# or use token-based authentication:
# argocd login <ARGOCD_SERVER_ADDRESS> --username <USERNAME> --token <TOKEN>
- Get context names
kubectl config get-contexts
copy context name for prod cluster <CLUSTER_CONTEXT_NAME>
- Add Cluster Contexts Use the
argocd cluster addcommand to add Kubernetes cluster as a context to ArgoCD. For example:
argocd cluster add <CLUSTER_CONTEXT_NAME>
- Verify Connected Clusters You can verify the clusters connected to ArgoCD using the following command:
argocd cluster list
This will list all the clusters that are connected to your ArgoCD instance.
- Open argoCD UI and check under setting >> cluster you will see your second cluster is added but status will be
unknowndon't worry just deploy app it will showsuccessful

- Create Applications With the clusters connected, you can now create applications in ArgoCD that deploy resources to specific clusters , and how to create application. I have covered in my previous blog on argocd

app in the dev cluster

app in the prod cluster

Sync Applications ArgoCD will automatically sync the applications with their respective clusters based on the specified context and Git repository.
Conclusion
By following these steps, you can easily add multiple Kubernetes clusters to ArgoCD and manage your applications across various clusters from a single ArgoCD instance. ArgoCD's ability to handle multiple clusters simplifies the process of deploying applications in complex multi-cluster environments. Embrace the power of ArgoCD to streamline your application deployments and manage your Kubernetes clusters efficiently. Happy deploying!



