3 min read
Multi-Region Cloud Training, Part 2: GitOps with Argo CD
Running kubectl apply by hand against two clusters leads to configuration drift and slow rollbacks. Here we set up Argo CD as a single control plane that watches Git and reconciles both clusters from cluster labels.
[GitHub Repo (manifests)]
│
▼
[Argo CD (control)]
╱ ╲
▼ ▼
[Cluster US] [Cluster EU]
(syncs us) (syncs eu)Installing Argo CD and Registering Clusters
Install Argo CD in your control cluster (or both clusters using task argocd:install:all from the repo Taskfile.yml):
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm --kube-context prod-us-east-1 upgrade --install argocd argo/argo-cd \
-n argocd --create-namespace \
--set server.service.type=LoadBalancer \
--waitLog in with the Argo CD CLI before registering clusters (argocd login <ARGOCD_SERVER> using the initial password in secret argocd-initial-admin-secret, or port-forward svc/argocd-server locally).
Register both target clusters with an explicit region label. The ApplicationSet cluster generator reads labels from Argo CD’s registered cluster Secrets in the argocd namespace, not from Kubernetes namespace labels.
argocd cluster add prod-us-east-1 --name prod-us --label region=us --yes
argocd cluster add prod-eu-west-1 --name prod-eu --label region=eu --yesWriting the ApplicationSet
Instead of maintaining a separate Application per cluster, an ApplicationSet templates one Application per registered cluster matching region in [us, eu] and selects its overlay path from metadata.labels.region.
Save this as deploy/apps/echo-appset.yaml:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: echo-multicluster
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters:
selector:
matchExpressions:
- key: region
operator: In
values: ["us", "eu"]
template:
metadata:
name: 'echo-{{.name}}'
spec:
project: default
destination:
server: '{{.server}}'
namespace: echo
source:
repoURL: https://github.com/your-org/your-repo
targetRevision: main
path: deploy/overlays/{{.metadata.labels.region}}/echo
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=trueA few details worth calling out:
goTemplate: truewithmissingkey=errorreplaces the deprecatedfasttemplateengine ({{name}}) and fails fast if a cluster is missing theregionlabel.CreateNamespace=trueensures Argo CD creates theechonamespace on each target cluster before applying manifests.path: deploy/overlays/{{.metadata.labels.region}}/echomatches theDeploymentoverlays we build in Parts 5 through 7. In Part 7.1, when we migrate to Argo Rollouts, we switch todeploy/rollouts/overlays/{{.metadata.labels.region}}and addignoreDifferencessoselfHeal: truedoes not overwrite live traffic weights (see deploy/apps/rollouts-appset.yaml in this repo).
Verification
Apply the ApplicationSet to your control cluster:
kubectl --context prod-us-east-1 -n argocd apply -f deploy/apps/echo-appset.yamlList the generated applications:
argocd app listYou should see echo-prod-us and echo-prod-eu. Until we commit the overlay manifests in Part 5, both applications will show a sync error for the missing path; once Part 5 is pushed, their status should move to Synced and Healthy, and the echo namespace will exist in both clusters.
Next, we install Istio across both clusters and wire up cross-cluster traffic.