Cluster Generator for Multi-Environment
What you'll learn: How to use ArgoCD's cluster generator to automatically deploy identical applications across multiple Kubernetes clusters with environment-specific configurations.
The Core Challenge
You've learned how ApplicationSets create multiple applications dynamically. But what if you need to deploy the same application to multiple clusters—staging, production, DR—each with slightly different configurations? Manually creating an Application per cluster doesn't scale.
What is the Cluster Generator?
The cluster generator is an ApplicationSet generator that discovers all registered clusters in ArgoCD and creates one Application per cluster automatically. Think of it like a mail-merge for Kubernetes deployments: one template, many destinations.
When you register a cluster with ArgoCD, the cluster generator sees it and can use its metadata (name, labels, URL) to parameterize your application deployment.
Basic Structure
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: my-app-multi-cluster
spec:
generators:
- clusters:
selector:
matchLabels:
environment: production # Only prod clusters
template:
metadata:
name: '{{name}}-my-app'
spec:
project: default
source:
repoURL: https://github.com/org/my-app
targetRevision: HEAD
path: overlays/{{metadata.labels.environment}}
destination:
server: '{{server}}'
namespace: my-app
Each cluster becomes variables like {{name}}, {{server}}, and {{metadata.labels.*}} that customize the deployment. Use label selectors to target specific cluster subsets.
Key Takeaway: The cluster generator automatically creates Applications for every registered cluster matching your selector, enabling true multi-cluster GitOps with environment-specific paths or values based on cluster metadata.