|
1 | 1 | --- |
2 | 2 | title:"Add external clusters to GitOps Runtimes" |
3 | | -description:"Manage multiple remote clusters withsingle GitOps Runtime" |
| 3 | +description:"Manage multiple remote clusters witha GitOps Runtime" |
4 | 4 | group:installation |
5 | 5 | sub_group:gitops |
6 | 6 | toc:true |
7 | 7 | --- |
8 | 8 |
|
9 | | -Register external clusters to provisioned Hybrid or Hosted GitOps Runtimes in Codefresh. Once you add an external cluster, you can deploy applications to that cluster without having to install Argo CD on the clusters in order to do so. Manage multiple external clusters through a single Runtime. |
| 9 | +Once you have an Argo CD installation as part of a[hybrid]({{site.baseurl}}/docs/installation/gitops/hybrid-gitops/) or[hosted runtime]({{site.baseurl}}/docs/installation/gitops/hosted-runtime/) you |
| 10 | +can add external deployment clusters to them. |
10 | 11 |
|
11 | | -When you add an external cluster to a provisioned GitOps Runtime, the cluster is registered as a managed cluster. A managed cluster is treated as any other managed K8s resource, meaning thatyou canmonitor its health and sync status,deploy applications toit, view information in the Applications dashboard, and remove thecluster from the Runtime's managed list. |
| 12 | +Once you add an external cluster,you can deploy applications tothat cluster without having to install Argo CD on theclusters in order to do so. |
12 | 13 |
|
13 | | -Add managed clusters through: |
14 | | -* GitOps CLI |
15 | | -* Kustomize |
| 14 | +When you add an external cluster to a provisioned GitOps Runtime, the cluster is registered as a managed cluster. A managed cluster is treated as any other managed K8s resource, meaning that you can monitor its health and sync status, deploy applications to it, view information in the Applications dashboard, and remove the cluster from the Runtime's managed list. |
16 | 15 |
|
17 | 16 | Adding a managed cluster via Codefresh ensures that Codefresh applies the required RBAC resources (`ServiceAccount`,`ClusterRole` and`ClusterRoleBinding`) to the target cluster, creates a`Job` that updates the selected Runtime with the information, registers the cluster in Argo CD as a managed cluster, and updates the platform with the new cluster information. |
18 | 17 |
|
19 | 18 |
|
20 | | -##Add a managed cluster with GitOps CLI |
21 | | -Add an external cluster to a provisioned GitOps Runtime through the GitOps CLI. When adding the cluster, you can also add labels and annotations to the cluster, which are added to the cluster secret created by Argo CD. |
22 | | -Optionally, to first generate the YAML manifests, and then manually apply them, use the`dry-run` flag in the CLI. |
23 | 19 |
|
24 | | -**Before you begin** |
| 20 | + |
| 21 | +##Prerequisites |
25 | 22 |
|
26 | 23 | * For_Hosted GitOps_ Runtimes:[Configure access to these IP addresses]({{site.baseurl}}/docs/administration/platform-ip-addresses/) |
27 | | -* Verify that: |
28 | | -* Your Git personal access token is valid and has the[required scopes]({{site.baseurl}}/docs/reference/git-tokens) |
29 | | -* You have the[latest version of the Codefresh CLI]({{site.baseurl}}/docs/installation/gitops/upgrade-gitops-cli/) |
| 24 | +* Your Git personal access token is valid and has the[required scopes]({{site.baseurl}}/docs/reference/git-tokens) |
| 25 | +* You have the[latest version of the Codefresh CLI]({{site.baseurl}}/docs/installation/gitops/upgrade-gitops-cli/) |
| 26 | +* You have created a Codefresh token in user settings |
| 27 | +* You know the ingress host of your runtime using`cf runtime list` |
| 28 | + |
| 29 | +###Add a managed cluster with GitOps CLI |
| 30 | +Add an external cluster to a provisioned GitOps Runtime through the GitOps CLI. When adding the cluster, you can also add labels and annotations to the cluster, which are added to the cluster secret created by Argo CD. |
| 31 | +Optionally, to first generate the YAML manifests, and then manually apply them, use the`dry-run` flag in the CLI. |
30 | 32 |
|
31 | 33 | **How to** |
32 | 34 |
|
@@ -59,174 +61,53 @@ Optionally, to first generate the YAML manifests, and then manually apply them, |
59 | 61 | Here is an example of the YAML manifest generated with the`--dry-run` flag. Note that the example has placeholders, which are replaced with the actual values during the`--dry-run`. |
60 | 62 |
|
61 | 63 |
|
62 | | -```yaml |
63 | | -apiVersion:v1 |
64 | | -kind:ServiceAccount |
65 | | -metadata: |
66 | | -name:argocd-manager |
67 | | -namespace:kube-system |
68 | | ---- |
69 | | -apiVersion:rbac.authorization.k8s.io/v1 |
70 | | -kind:ClusterRole |
71 | | -metadata: |
72 | | -name:argocd-manager-role |
73 | | -rules: |
74 | | --apiGroups: |
75 | | - -'*' |
76 | | -resources: |
77 | | - -'*' |
78 | | -verbs: |
79 | | - -'*' |
80 | | --nonResourceURLs: |
81 | | - -'*' |
82 | | -verbs: |
83 | | - -'*' |
84 | | ---- |
85 | | -apiVersion:rbac.authorization.k8s.io/v1 |
86 | | -kind:ClusterRoleBinding |
87 | | -metadata: |
88 | | -name:argocd-manager-role-binding |
89 | | -roleRef: |
90 | | -apiGroup:rbac.authorization.k8s.io |
91 | | -kind:ClusterRole |
92 | | -name:argocd-manager-role |
93 | | -subjects: |
94 | | --kind:ServiceAccount |
95 | | -name:argocd-manager |
96 | | -namespace:kube-system |
97 | | ---- |
98 | | -apiVersion:v1 |
99 | | -data: |
100 | | -contextName:<context-name> |
101 | | -ingressUrl:<ingressUrl> |
102 | | -server:<server> |
103 | | -kind:ConfigMap |
104 | | -metadata: |
105 | | -name:csdp-add-cluster-cm |
106 | | -namespace:kube-system |
107 | | ---- |
108 | | -apiVersion:v1 |
109 | | -data: |
110 | | -annotations:| |
111 | | - <annotation-key1>:<annotation-value1> |
112 | | - <annotation-key2>:<annotation-value2> |
113 | | -contextName:<context-name> |
114 | | -ingressUrl:ingressurl.com |
115 | | -labels:| |
116 | | - <label-key1>:<label-value1> |
117 | | - <label-key2>:<label-value2> |
118 | | -server:https://<hash>.gr7.us-east-1.eks.amazonaws.com/ |
119 | | -csdpToken:<csdpToken> |
120 | | -kind:Secret |
121 | | -metadata: |
122 | | -name:csdp-add-cluster-secret |
123 | | -namespace:kube-system |
124 | | -type:Opaque |
125 | | ---- |
126 | | -apiVersion:batch/v1 |
127 | | -kind:Job |
128 | | -metadata: |
129 | | -name:csdp-add-cluster-job |
130 | | -namespace:kube-system |
131 | | -spec: |
132 | | -template: |
133 | | -metadata: |
134 | | -name:csdp-add-cluster-pod |
135 | | -spec: |
136 | | -containers: |
137 | | - -args: |
138 | | - -./add-cluster.sh |
139 | | -command: |
140 | | - -bash |
141 | | -env: |
142 | | - -name:SERVICE_ACCOUNT_NAME |
143 | | -valueFrom: |
144 | | -fieldRef: |
145 | | -fieldPath:spec.serviceAccountName |
146 | | - -name:INGRESS_URL |
147 | | -valueFrom: |
148 | | -configMapKeyRef: |
149 | | -key:ingressUrl |
150 | | -name:csdp-add-cluster-cm |
151 | | - -name:CSDP_TOKEN |
152 | | -valueFrom: |
153 | | -secretKeyRef: |
154 | | -key:csdpToken |
155 | | -name:csdp-add-cluster-secret |
156 | | - -name:CONTEXT_NAME |
157 | | -valueFrom: |
158 | | -configMapKeyRef: |
159 | | -key:contextName |
160 | | -name:csdp-add-cluster-cm |
161 | | - -name:SERVER |
162 | | -valueFrom: |
163 | | -configMapKeyRef: |
164 | | -key:server |
165 | | -name:csdp-add-cluster-cm |
166 | | -image:quay.io/codefresh/csdp-add-cluster:0.1.0 |
167 | | -imagePullPolicy:Always |
168 | | -name:main |
169 | | -resources: |
170 | | -limits: |
171 | | -cpu:"1" |
172 | | -memory:512Mi |
173 | | -requests: |
174 | | -cpu:"0.2" |
175 | | -memory:256Mi |
176 | | -restartPolicy:Never |
177 | | -serviceAccount:argocd-manager |
178 | | -ttlSecondsAfterFinished:600 |
| 64 | +The new cluster is registered to the GitOps Runtime as a managed cluster. |
179 | 65 |
|
180 | | -``` |
| 66 | +###Add a managed cluster with Kustomize |
181 | 67 |
|
182 | | -The new cluster is registered to the GitOps Runtime as a managed cluster. |
| 68 | +1. Clone locally[https://github.com/codefresh-io/csdp-official/tree/main/add-cluster/kustomize](https://github.com/codefresh-io/csdp-official/tree/main/add-cluster/kustomize). |
| 69 | +1. Update confimap.yml and secret.yml with the require values |
| 70 | +1. Run`kustomize build` or`kubectl -k` to apply the final result to the cluster |
| 71 | + |
| 72 | +You can get the`ingressUrl` value of your runtime by running`cf runtime list` in your terminal |
| 73 | +after authenticating to the[Codefresh GitOps CLI]({{site.baseurl}}/docs/installation/cli/). |
| 74 | + |
| 75 | +###Add a managed cluster with Helm |
| 76 | + |
| 77 | +A Helm chart is published athttps://chartmuseum.codefresh.io/csdp-add-cluster. You can see the source templates at[https://github.com/codefresh-io/csdp-official/tree/main/add-cluster/helm](https://github.com/codefresh-io/csdp-official/tree/main/add-cluster/helm). |
| 78 | + |
| 79 | +To deploy the chart copy locally[https://github.com/codefresh-io/csdp-official/blob/main/add-cluster/helm/values.yaml](https://github.com/codefresh-io/csdp-official/blob/main/add-cluster/helm/values.yaml) and fill in the required values. |
| 80 | + |
| 81 | +Then run |
| 82 | + |
| 83 | +```shell |
| 84 | +helm repo add csdp-add-cluster https://chartmuseum.codefresh.io/csdp-add-cluster |
| 85 | +helm search repo csdp-add-cluster |
| 86 | +helm install csdp-add-cluster/csdp-add-cluster -f values.yaml --generate-name |
| 87 | +``` |
183 | 88 |
|
184 | | -##Add a managed cluster with Kustomize |
185 | | - |
186 | | -Create a`kustomization.yaml` file with the information shown in the example below, and run`kustomize build` on it. |
187 | | - |
188 | | -```yaml |
189 | | -apiVersion:kustomize.config.k8s.io/v1beta1 |
190 | | -kind:Kustomization |
191 | | -namespace:kube-system |
192 | | - |
193 | | -configMapGenerator: |
194 | | - -name:csdp-add-cluster-cm |
195 | | -namespace:kube-system |
196 | | -behavior:merge |
197 | | -literals: |
198 | | -# contextName is the name of the kube context (in the local kubeconfig file) that connects to the target cluster |
199 | | - -"contextName=<contextName>" |
200 | | -# ingressUrl is the url used to access the Codefresh runtime |
201 | | -# example https://some.domain.name |
202 | | - -"ingressUrl=<ingressUrl>" |
203 | | -# server is the k8s cluster API endpoint url |
204 | | -# can be obtained by |
205 | | -# CONTEXT_NAME=<TARGET_CONTEXT_NAME> |
206 | | -# CLUSTER_NAME=$(kubectl config view --raw --flatten -o jsonpath='{.contexts[?(@.name == "'"${CONTEXT_NAME}"'")].context.cluster}') |
207 | | -# kubectl config view --raw --flatten -o jsonpath='{.clusters[?(@.name == "'"${CLUSTER_NAME}"'")].cluster.server}' |
208 | | - -"server=https://<hash>.gr7.us-east-1.eks.amazonaws.com/" |
209 | | - -| |
210 | | - annotations=<key1: value1> |
211 | | - <key2.with.dots/and-backslash: value2 with: as:pace> |
212 | | - -| |
213 | | - labels=<and.another-one/field: value> |
214 | | - <label.key.with.long.name/field: some_long_value> |
215 | | -
|
216 | | -secretGenerator: |
217 | | --behavior:merge |
218 | | -literals: |
219 | | - -csdpToken=<your-personal-token> |
220 | | -name:csdp-add-cluster-secret |
221 | | -namespace:kube-system |
222 | | - |
223 | | -resources: |
224 | | - -https://github.com/codefresh-io/csdp-official/add-cluster/kustomize?ref=<runtimeVersion> |
225 | | -``` |
226 | 89 |
|
227 | 90 | You can get the`ingressUrl` value of your runtime by running`cf runtime list` in your terminal |
228 | 91 | after authenticating to the[Codefresh GitOps CLI]({{site.baseurl}}/docs/installation/cli/). |
229 | 92 |
|
| 93 | +###Add a manage cluster with Terraform |
| 94 | + |
| 95 | +Use the[Helm provider](https://registry.terraform.io/providers/hashicorp/helm/latest/docs) as any other Helm chart. |
| 96 | + |
| 97 | +```hcl |
| 98 | +resource "helm_release" "my-managed-cluster" { |
| 99 | + name = "my-managed-cluster" |
| 100 | +
|
| 101 | + repository = "https://chartmuseum.codefresh.io/csdp-add-cluster" |
| 102 | + chart = "csdp-add-cluster" |
| 103 | + values = [ |
| 104 | + "${file("values.yaml")}" |
| 105 | + ] |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +And then apply the file using Terraform or your favorite workflow tool. |
| 110 | + |
230 | 111 | ##Work with managed clusters |
231 | 112 | Work with managed clusters in either the Topology or List Runtime views. For information on Runtime views, see[Runtime views]({{site.baseurl}}/docs/installation/gitops/monitor-manage-runtimes/#gitops-runtime-views). |
232 | 113 | As the cluster is managed through the Runtime, updates to the Runtime automatically updates the components on all the managed clusters that include it. |
@@ -254,6 +135,12 @@ Install Argo Rollouts with a single click to execute rollout instructions, deplo |
254 | 135 | max-width="40%" |
255 | 136 | %} |
256 | 137 |
|
| 138 | +##Remove a managed cluster |
| 139 | + |
| 140 | +When you want to remove a cluster as a deployment target you can unlink it from the runtime that manages it. |
| 141 | + |
| 142 | +Note that this only removes the management link between your runtime and your cluster. It doesn't do anything with the applications that are already running on the cluster. |
| 143 | + |
257 | 144 |
|
258 | 145 | ###Remove a managed cluster from the Codefresh UI |
259 | 146 | Remove a cluster from the Runtime's list of managed clusters from the Codefresh UI. |
@@ -288,6 +175,22 @@ Remove a cluster from the list managed by the GitOps Runtime, through the GitOp |
288 | 175 | `<server-url>` is the URL of the server on which the managed cluster is installed. |
289 | 176 |
|
290 | 177 |
|
| 178 | + |
| 179 | + |
| 180 | +###Remove with Kustomize |
| 181 | + |
| 182 | +Run`kubectl delete -f <your_yaml>` with the result of the`kustomize build` command |
| 183 | +that you run during installation |
| 184 | + |
| 185 | +###Remove with Helm |
| 186 | + |
| 187 | +Run`helm delete <release_name>` with the name of the release that was created |
| 188 | +during installation. |
| 189 | + |
| 190 | +###Remove with terraform |
| 191 | + |
| 192 | +Use the`terraform destroy` command. |
| 193 | + |
291 | 194 | ##Related articles |
292 | 195 | [Add Git Sources to GitOps Runtimes]({{site.baseurl}}/docs/installation/gitops/git-sources/) |
293 | | -[Monitoring & managing GitOps Runtimes]({{site.baseurl}}/docs/installation/gitops/monitor-manage-runtimes/) |
| 196 | +[Monitoring & managing GitOps Runtimes]({{site.baseurl}}/docs/installation/gitops/monitor-manage-runtimes/) |