ApplicationSets: Generate Applications from Templates
Practicing the ApplicationSet
You've deployed todo-app to a single namespace from two sources.
Here is what we did previously (we're going to use this as a starting point):
cat < $HOME/todo/app/manifests/app-multi-source.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: todo-app
namespace: argocd
spec:
destination:
namespace: default
server: https://kubernetes.default.svc
project: default
sources:
- repoURL: $GITLAB_URL
targetRevision: main
ref: valsrc
- chart: todo
repoURL: $HELM_REPO_URL
targetRevision: 0.2.0
helm:
valueFiles:
- $valsrc/manifests/values-override.yaml
syncPolicy:
automated:
prune: true
selfHeal: true
allowEmpty: true
EOF
Now here's what we want to do: convert this into an ApplicationSet that deploys the same app to two namespaces on the same cluster, dev and prod, with different configuration per environment.
Produce 2 Applications from 1 ApplicationSet, with 1 Application per environment.
| Field | todo-dev | todo-prod |
|---|---|---|
| Namespace | dev | prod |
| replicaCount | 1 | 3 |
| Values file | values-dev.yaml | values-prod.yaml |
We will keep everything else the same as before: the destination cluster, the todo chart from $HELM_REPO_URL at 0.2.0, the values file loaded from Git through a ref source, auto-created namespaces, and automated sync with prune and self-heal.
You're done when these verifications pass:
# 2 Applications, generated from one file
kubectl get applications -n argocd
# Expect: todo-dev and todo-prod, both Synced/Healthy
# The per-namespace replica counts actually differ
kubectl get deploy -n dev todo -o jsonpath='{.spec.replicas}' # 1
kubectl get deploy -n prod todo -o jsonpath='{.spec.replicas}' # 3
Here's the solution.
First, create and commit the two values files. The starting point used a single values-override.yaml; the exercise needs one per environment, differing only in replicaCount.
cat < $HOME/todo/app/manifests/values-dev.yaml
replicaCount: 1
EOF
cat < $HOME/todo/app/manifests/values-prod.yaml
replicaCount: 3
EOF
Commit and push them, since the ref source reads from Git, not your local disk:
cd $HOME/todo/app && \
git add manifests/values-dev.yaml manifests/values-prod.yaml && \
git commit -m "Add per-environment values files for dev and prod" && \GitOps the Hard Way, with Argo CD
Build Real GitOps Pipelines From Empty Clusters to Automated DeploysEnroll now to unlock all content and receive all future updates for free.
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
