- in-cluster - where Argo CD runs,
https://kubernetes.default.svc (name in-cluster), no setup needed
- external - must be registered, needs credentials + network access from Argo CD to the API server
- one Argo CD (hub) can manage many clusters (spokes)
argocd cluster add <kube-context>
argocd cluster add <kube-context> --name production --label environment=production --label region=us-west-2
argocd cluster list
argocd cluster get https://prod-cluster.example.com
argocd cluster set <url> --name new-name --label tier=critical
argocd cluster rm <url>
cluster add uses your local kubeconfig and
- creates
argocd-manager ServiceAccount in kube-system of the target
- creates
argocd-manager-role ClusterRole (* on everything) + ClusterRoleBinding
- stores the token in a Secret in the
argocd namespace
- labels are used by the ApplicationSet cluster generator
- cluster = Secret with label
argocd.argoproj.io/secret-type: cluster
apiVersion: v1
kind: Secret
metadata:
name: production-cluster
namespace: argocd
labels:
argocd.argoproj.io/secret-type: cluster
environment: production
region: us-west-2
type: Opaque
stringData:
name: production
server: https://prod-cluster.example.com
config: |
{
"bearerToken": "<token>",
"tlsClientConfig": {
"insecure": false,
"caData": "<base64 CA>"
}
}
- restrict to namespaces:
namespaces: app-ns,monitoring (add clusterResources: "true" to still allow cluster-scoped kinds)
- point
spec.destination.server (or name) at the registered cluster
- the cluster must be allowed by the app’s
AppProject.spec.destinations
spec:
project: default
source:
repoURL: https://github.com/example/app.git
targetRevision: v1.0.0
path: kubernetes/production
destination:
server: https://prod-cluster.example.com
namespace: myapp
- cluster generator,
{{name}} and {{server}} come from the cluster Secret
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: myapp-multicluster
namespace: argocd
spec:
generators:
- clusters:
selector:
matchLabels:
environment: production
template:
metadata:
name: 'myapp-{{name}}'
spec:
project: default
source:
repoURL: https://github.com/example/app.git
targetRevision: main
path: kubernetes
destination:
server: '{{server}}'
namespace: myapp
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- the cluster generator without a selector matches all registered clusters (including in-cluster)
- cluster labels are available as
{{metadata.labels.region}}, clusters.values adds custom params ({{values.imageTag}})
list generator for per-environment values (revision, replicas)
matrix of clusters x git directories = every app on every cluster
- ApplicationSet
strategy.type: RollingSync updates apps in steps by label
- alpha, needs to be enabled on the ApplicationSet controller
strategy:
type: RollingSync
rollingSync:
steps:
- matchExpressions:
- key: stage
operator: In
values: ["1"]
- matchExpressions:
- key: stage
operator: In
values: ["2", "3"]
# template.metadata.labels: stage: '{{stage}}'
- Argo CD on the hub cluster, spokes registered with a label like
cluster-type: spoke
- ApplicationSet selects them with
matchLabels / matchExpressions and deploys clusters/{{name}} from a platform repo
sources:
- repoURL: https://github.com/example/app.git
path: helm
helm:
valueFiles:
- $values/regions/{{metadata.labels.region}}/values.yaml
- repoURL: https://github.com/example/config.git
ref: values