{"id":402,"date":"2024-04-25T11:39:01","date_gmt":"2024-04-25T11:39:01","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=402"},"modified":"2024-04-25T11:39:01","modified_gmt":"2024-04-25T11:39:01","slug":"configure-multiple-kubernetes-clusters-argo-cd","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=402","title":{"rendered":"How to Configure Multiple Kubernetes Clusters on ArgoCD"},"content":{"rendered":"<p>In this blog, you will learn how to configure and manage multiple Kubernetes clusters using Argo CD with step-by-step instructions.<\/p>\n<p><a href=\"https:\/\/devopscube.com\/argo-cd-ultimate-guide\/\">Argo CD<\/a> is a CD tool that has an amazing feature called <strong>multi-cluster support,<\/strong> which means you can deploy and manage applications not only in the cluster where Argo CD is installed but also in other external clusters.<\/p>\n<p>Argo CD will act as a central hub for every cluster, and Argo CD continuously sends API calls to every available cluster to keep them in sync and to check their health status.<\/p>\n<p>There is no specific limit to adding clusters to Argo CD. However, the cluster where Argo CD is deployed should have the required resources to handle the API calls sent and received from other clusters configured to it.<\/p>\n<p>The image below shows the two methods we can use to add a cluster to Argo CD.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/argocd-multi-cluster.png\" class=\"kg-image\" alt=\"Argo CD Multi cluster setup \" loading=\"lazy\" width=\"1580\" height=\"1778\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/08\/argocd-multi-cluster.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/08\/argocd-multi-cluster.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/08\/argocd-multi-cluster.png 1580w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"setup-prerequisites\">Setup Prerequisites<\/h2>\n<p>The following are the prerequisites for the setup.<\/p>\n<ol>\n<li>A running <a href=\"https:\/\/devopscube.com\/setup-argo-cd-using-helm\/\">Argo CD setup<\/a><\/li>\n<li><a href=\"https:\/\/devopscube.com\/setup-kubernetes-cluster-kubeadm\/\">Kubernetes Clusters<\/a> with permission to create ClusterRole<\/li>\n<li>Argo CD <a href=\"https:\/\/kostis-argo-cd.readthedocs.io\/en\/refresh-docs\/getting_started\/install_cli\/?ref=devopscube.com\">CLI<\/a><\/li>\n<li><a href=\"https:\/\/devopscube.com\/kubectl-set-context\/\">Kubectl<\/a> is configured on your workstation.<\/li>\n<\/ol>\n<h2 id=\"configuring-multiple-clusters-to-argo-cd\">Configuring Multiple Clusters to Argo CD<\/h2>\n<p>To configure multiple clusters in Argo CD there are primarily two methods. They are<\/p>\n<ol>\n<li>Using Argo CD Custom Resource Definitions (CRD)<\/li>\n<li>Using Argo CD CLI With Kubecofig files<\/li>\n<\/ol>\n<p>Let&#8217;s look at each method in detail.<\/p>\n<h3 id=\"method-1-argo-cd-crd-method\">Method 1: Argo CD CRD Method<\/h3>\n<p>Let&#8217;s see how to add multiple Kubernetes clusters to Argo CD using the CRD method.<\/p>\n<p>For the setup, I am using three Kubernetes Clusters. One Cluster has Argo CD installed, and the other two clusters will be added to Argo CD using the CRD method.<\/p>\n<p>Follow the below steps to add multiple clusters to Argo CD using the CRD method.<\/p>\n<p>In the below steps, do Step 1 and Step 2 on the clusters you are going to add to the Argo CD and Step 3 in the Argo CD cluster.<\/p>\n<h4 id=\"step-1-create-a-service-account\">Step 1: Create a Service Account<\/h4>\n<p>First, log in to Cluster which you need to add to Argo CD and start the RBAC configuration, create a YAML file, and copy the below content<\/p>\n<pre><code>apiVersion: v1\nkind: ServiceAccount\nmetadata:\n  name: argocd-manager\n  namespace: kube-system\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  name: argocd-manager-role\nrules:\n- apiGroups:\n  - '*'\n  resources:\n  - '*'\n  verbs:\n  - '*'\n- nonResourceURLs:\n  - '*'\n  verbs:\n  - '*'\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  name: argocd-manager-role-binding\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: ClusterRole\n  name: argocd-manager-role\nsubjects:\n- kind: ServiceAccount\n  name: argocd-manager\n  namespace: kube-system<\/code><\/pre>\n<p>This file will create a serviceaccount, a clusterrole with full cluster privileges, and bind the clusterrole to the serviceaccount.<\/p>\n<p>We are giving full cluster privileges because Argo CD needs full privileges on the cluster to create, delete, and manage applications on any namespace with the required resources.<\/p>\n<h4 id=\"step-2-create-a-secret\">Step 2: Create a Secret<\/h4>\n<p>The next step is to create the Bearer Token and configure it to the service account we created in Step 1.<\/p>\n<p>Create another YAML file and copy the content below. This will create a token for the service account <code>argocd-manager<\/code>.<\/p>\n<pre><code>apiVersion: v1\nkind: Secret\nmetadata:\n  name: argocd-manager-token\n  namespace: kube-system\n  annotations:\n    kubernetes.io\/service-account.name: argocd-manager\ntype: kubernetes.io\/service-account-token<\/code><\/pre>\n<p>Once the secret has been created save the token and CA certificate as variables so that we can use them in the next step.<\/p>\n<p>Run the following command to save the bearer token and CA certificate as a variable<\/p>\n<pre><code>ca=$(kubectl get -n kube-system secret\/argocd-manager-token -o jsonpath='{.data.ca\\.crt}')\n\ntoken=$(kubectl get -n kube-system secret\/argocd-manager-token -o jsonpath='{.data.token}' | base64 --decode)<\/code><\/pre>\n<h4 id=\"step-3-create-a-secret-in-the-argo-cd-cluster\">Step 3: Create a Secret in the Argo CD Cluster<\/h4>\n<p>To complete the RBAC configuration, log in to the Argo CD cluster and create a Secret with the data Argo CD needs to connect with other clusters.<\/p>\n<p>Run the following command to create the secret<\/p>\n<pre><code>cat &lt;&lt;EOF | kubectl apply -n argocd -f -\napiVersion: v1\nkind: Secret\nmetadata:\n  name: cluster1-secret\n  labels:\n    argocd.argoproj.io\/secret-type: cluster\ntype: Opaque\nstringData:\n  name: cluster-1\n  server: https:\/\/B66A3A2BB2.**************\n  config: |\n    {\n      \"bearerToken\": \"${token}\",\n      \"tlsClientConfig\": {\n        \"serverName\": \"B66A3A2BB2.************\",\n        \"caData\": \"${ca}\"\n      }\n    }\nEOF<\/code><\/pre>\n<p>In this command, make sure to update your cluster endpoint in the above command.<\/p>\n<p>Also, you can see it gets the bearer token and CA certificate from the variable we created in Step 2.<\/p>\n<p>Repeat the same steps to the cluster you need to add to Argo CD and change the secret name and cluster name when configuring the other clusters.<\/p>\n<p>Once you have run the above command, if you check under the option <strong>Setting-&gt;Clusters<\/strong> on Argo CD UI, you can see a new cluster as shown below<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-135-9.png\" class=\"kg-image\" alt=\"new clusters are added to Argo CD\" loading=\"lazy\" width=\"2000\" height=\"988\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-135-9.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-135-9.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-135-9.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-135-9.png 2238w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>If you want to deploy an application on the new cluster, you can select between clusters while adding a <strong>NEW APP<\/strong> as shown below<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-117-7.png\" class=\"kg-image\" alt=\"Argo CD dashboard\" loading=\"lazy\" width=\"1670\" height=\"938\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-117-7.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-117-7.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-117-7.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-117-7.png 1670w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>After selecting the <strong>NEW APP<\/strong> button a new page will open, scroll down to the <strong>DESTINATION<\/strong> tag where you can select between available clusters as shown below<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-133-8.png\" class=\"kg-image\" alt=\"selecting between cluster for deployment\" loading=\"lazy\" width=\"876\" height=\"404\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-133-8.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-133-8.png 876w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Using the <strong>DESTINATION<\/strong> tab you can select the cluster in which you want to deploy the application using Argo CD.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-136-5.png\" class=\"kg-image\" alt=\"application deployed in different clusters\" loading=\"lazy\" width=\"1094\" height=\"569\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-136-5.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-136-5.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-136-5.png 1094w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>You can see in the above image the two applications are deployed in two different clusters.<\/p>\n<h3 id=\"method-2-using-argo-cd-cli-with-kubeconfig-file\">Method 2: Using Argo CD CLI with Kubeconfig File<\/h3>\n<p>You can also configure multiple clusters from the <a href=\"https:\/\/devopscube.com\/kubernetes-kubeconfig-file\/\">Kubeconfig file<\/a> you have on your workstation assuming you have the Argo CD CLI configured on your system.<\/p>\n<p>Argo CD CLI can read the contexts from the Kubeconfig file and use the credentials from the Kubeconfig.<\/p>\n<p>For the setup, I am using two AWS EKS clusters from the same account, you can use the cluster of any Cloud platform.<\/p>\n<h4 id=\"step-1-login-to-argo-cd\">Step 1: Login to Argo CD<\/h4>\n<p>Make sure that you have updated the cluster details to the <strong>kubeconfig<\/strong> file and logged into Argo CD using Argo CD CLI, if not run the following command to log in to Argo CD.<\/p>\n<pre><code>argocd login &lt;url&gt;:&lt;port&gt; --username &lt;username&gt; --password &lt;password&gt;<\/code><\/pre>\n<p>With this command, you can log in to Argo CD using the username and password.<\/p>\n<h4 id=\"step-2-get-the-context-of-the-cluster\">Step 2: Get the Context of the Cluster<\/h4>\n<p>Once you have logged in to Argo CD, you need to find the context of the cluster you need to add to Argo CD.<\/p>\n<p>Run the following command to get the context from the <strong>kubeconfig<\/strong> file<\/p>\n<pre><code>kubectl config get-contexts -o name<\/code><\/pre>\n<p>You will get the list of cluster contexts that are configured in the kubeconfig file.<\/p>\n<h4 id=\"step-3-add-the-cluster\">Step 3: Add the Cluster<\/h4>\n<p>To add the cluster to Argo CD, use the context of the running cluster you got from the previous step on the below command<\/p>\n<pre><code>argocd cluster add --kubeconfig &lt;path-of-kubeconfig-file&gt; --kube-context string &lt;cluster-context&gt; --name &lt;cluster-name&gt;<\/code><\/pre>\n<p>Make sure to add the cluster context in the above command.<\/p>\n<p>This command will create a <strong>service account Argo CD-manager<\/strong> on the cluster you specify in the above command with full cluster privileges, so make sure you have the required permissions on the cluster.<\/p>\n<p>If adding the cluster to Argo CD is successful you will get the following output in return<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-138-5.png\" class=\"kg-image\" alt=\"output got after successfully adding the cluster usinf Argo CD cli\" loading=\"lazy\" width=\"790\" height=\"329\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-138-5.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-138-5.png 790w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>After getting the above output, you can see a new cluster has been added to Argo CD in the UI.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this blog, you learned two methods of adding multiple clusters to Argo CD, one is using the Argo CD CRD method, and another method is using Argo CD CLI.<\/p>\n<p>I hope you find this blog useful for adding multiple clusters to Argo CD using simple steps.<\/p>\n<p>If you face any issues during the configuration, do let us know in the comments section. We will take a look.<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83c\udf81<\/div>\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Bonus:<\/strong><\/b> Here is a free study guide for <a href=\"https:\/\/devopscube.com\/certified-argo-project-associate\/\">Certified Argo Project Associate (CAPA)<\/a>.<\/div>\n<\/div>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/configure-multiple-kubernetes-clusters-argo-cd\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Configure Multiple Kubernetes Clusters on ArgoCD \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/configure-multiple-kubernetes-clusters-argo-cd\/<\/p>\n","protected":false},"author":1,"featured_media":403,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/402\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/403"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}