Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Multi-Cluster

In-cluster vs. external

  • 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)

Adding a cluster

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

Declarative

  • 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)

Credential types

  • ServiceAccount bearer token (bearerToken) - default for cluster add
  • client cert (tlsClientConfig.certData + keyData)
  • exec provider (execProviderConfig) for cloud auth, the binary must exist in the Argo CD image
  • EKS: awsAuthConfig (clusterName, optional roleARN), Argo CD’s SA uses IRSA (eks.amazonaws.com/role-arn annotation on argocd-application-controller and argocd-server)
    { "awsAuthConfig": { "clusterName": "my-cluster" }, "tlsClientConfig": { "caData": "..." } }
    
  • GKE: workload identity or execProviderConfig with gke-gcloud-auth-plugin
  • AKS: workload identity, or execProviderConfig with kubelogin
  • rotate credentials regularly

Deploying across clusters

  • point spec.destination.server (or name) at the registered cluster
  • the cluster must be allowed by the app’s AppProject.spec.destinations

One app per cluster

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

ApplicationSet

  • 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

Progressive rollout

  • 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}}'

Hub and spoke

  • 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

Multiple sources per region

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