Skip to content
CNPE · Chapter 6 of 22 Day 4: Argo CD for teams – projects, ApplicationSets, promotion

Day 4: Argo CD for teams – projects, ApplicationSets, promotion

Goal: Team Green gets its own Argo CD project with limits, environments as Kustomize overlays, an ApplicationSet that generates an Application for each environment by itself, and a path to production via a pull request · Duration: approx. 75 min · Prerequisite: Day 3

Briefing

  • One hand-written Application per service and environment does not scale. A platform needs three things:
Building block Task
AppProject A team’s limits: which repos, which destination namespaces, which resources
Kustomize overlays one base, only the differences per environment
ApplicationSet generates Applications from a template and a generator
  • Promotion means: taking a version that runs in staging to prod. With GitOps this is a change in Git – and for prod one that someone reviews: a pull request.
  • Generators you should know: list (fixed list), git (directories or files in the repo), cluster (registered clusters), matrix/merge (combinations). Today you use the Git generator: a new directory in the repo becomes a new Application.

Drill 1: One base, two environments

You delete the Application team-green-shop from Day 3 without taking its objects with it – the ApplicationSet will take them over shortly:

# on cp1
#   --cascade=orphan   delete only the Application, Deployment, Service, ConfigMap stay
k -n argocd delete application team-green-shop --cascade=orphan
cd ~/cnpe/plattform && git pull -q
S=apps/team-green/shop
mkdir -p $S/base $S/overlays/staging $S/overlays/prod
# the existing manifests become the base; the migration from Day 3 is dropped
git mv $S/deployment.yaml $S/service.yaml $S/config.yaml $S/base/
git rm -q $S/migration.yaml
# remove the namespace from the base – each environment sets it itself
sed -i '/namespace: team-green/d' $S/base/*.yaml
cat > $S/base/kustomization.yaml <<'EOF'
resources:
- deployment.yaml
- service.yaml
- config.yaml
EOF
cat > $S/overlays/staging/kustomization.yaml <<'EOF'
namespace: team-green-staging     # all objects into this namespace
resources:
- ../../base
replicas:                         # replica count per environment
- name: shop
  count: 1
images:                           # image tag per environment – this is where promotion happens
- name: nginx
  newTag: "1.29"
EOF
cat > $S/overlays/prod/kustomization.yaml <<'EOF'
namespace: team-green
resources:
- ../../base
replicas:
- name: shop
  count: 2
images:
- name: nginx
  newTag: "1.29"
EOF
# this is what staging looks like rendered
k kustomize $S/overlays/staging | grep -E 'namespace:|replicas:|image:'
git add -A && git commit -qm 'shop: Kustomize mit staging und prod' && git push -q

Expected:

application.argoproj.io "team-green-shop" deleted from argocd namespace
  namespace: team-green-staging
  namespace: team-green-staging
  namespace: team-green-staging
  replicas: 1
      - image: nginx:1.29

Save your progress? Sign up for free

Drill 2: Team Green’s project

The project default allows everything. Team Green gets its own limits:

# on cp1
mkdir -p ~/cnpe/tag04 && cd ~/cnpe/tag04
cat > projekt-team-green.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: team-green
  namespace: argocd
spec:
  description: Anwendungen von Team Green
  sourceRepos:                         # only from this repo
  - http://172.16.0.126:30300/platform/plattform.git
  destinations:                        # only into these namespaces (wildcard * allowed)
  - server: https://kubernetes.default.svc
    namespace: team-green
  - server: https://kubernetes.default.svc
    namespace: team-green-*
  clusterResourceWhitelist:            # cluster-wide objects: only namespaces (for CreateNamespace)
  - group: ""
    kind: Namespace
  namespaceResourceBlacklist:          # the team may not touch the fences from Day 1
  - group: ""
    kind: ResourceQuota
  - group: ""
    kind: LimitRange
  - group: networking.k8s.io
    kind: NetworkPolicy
EOF
k apply -f projekt-team-green.yaml
argocd proj get team-green

Expected (abridged):

appproject.argoproj.io/team-green created
Name:                        team-green
Description:                 Anwendungen von Team Green
Destinations:                https://kubernetes.default.svc,team-green
                             https://kubernetes.default.svc,team-green-*
Repositories:                http://172.16.0.126:30300/platform/plattform.git
...
Allowed Cluster Resources:   /Namespace
...
Denied Namespaced Resources: /ResourceQuota
                             /LimitRange
                             networking.k8s.io/NetworkPolicy

Save your progress? Sign up for free

Drill 3: The ApplicationSet

The Git generator finds every directory apps/team-green/<service>/overlays/<environment>. For each one, the template generates an Application.

# on cp1
cat > appset-team-green.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: team-green
  namespace: argocd
spec:
  goTemplate: true                     # templates in Go template syntax
  goTemplateOptions: ["missingkey=error"]   # typos in variables = error instead of empty text
  generators:
  - git:
      repoURL: http://172.16.0.126:30300/platform/plattform.git
      revision: main
      requeueAfterSeconds: 30          # check the repo every 30 s (default: 180 s)
      directories:
      - path: apps/team-green/*/overlays/*
  template:
    metadata:
      # path.segments: [apps, team-green, shop, overlays, staging] → index 2 = service
      name: "team-green-{{ index .path.segments 2 }}-{{ .path.basename }}"
    spec:
      project: team-green
      source:
        repoURL: http://172.16.0.126:30300/platform/plattform.git
        targetRevision: main
        path: "{{ .path.path }}"
      destination:
        server: https://kubernetes.default.svc
        # prod → team-green, everything else → team-green-<environment>
        namespace: '{{ if eq .path.basename "prod" }}team-green{{ else }}team-green-{{ .path.basename }}{{ end }}'
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true         # create the missing namespace ...
        managedNamespaceMetadata:      # ... with these labels
          labels:
            team: green
            tier: tenant
EOF
k apply -f appset-team-green.yaml
sleep 45
argocd app list
k get ns -l team=green

Expected (abridged):

applicationset.argoproj.io/team-green created
NAME                            CLUSTER                         NAMESPACE           PROJECT     STATUS  HEALTH   SYNCPOLICY
argocd/team-green-shop-prod     https://kubernetes.default.svc  team-green          team-green  Synced  Healthy  Auto-Prune
argocd/team-green-shop-staging  https://kubernetes.default.svc  team-green-staging  team-green  Synced  Healthy  Auto-Prune
NAME                 STATUS   AGE
team-green           Active   35m
team-green-staging   Active   35s

Two pitfalls that really occurred while building this ApplicationSet:

  • Without destination.namespace, the ApplicationSet generates the Applications, but they remain Unknown with InvalidSpecError: namespace ’’ do not match any of the allowed destinations in project ‘team-green’. The project only allows named namespaces – “no namespace” is not one of them. The message is in k -n argocd get application <name> -o jsonpath='{.status.conditions}'.
  • Double quotes in the template need single quotes on the outside: namespace: '{{ if eq … "prod" }}…'. With double quotes on the outside, the YAML parser aborts (did not find expected key).

team-green-shop-prod has taken over the orphaned objects from Day 3: same name, same namespace – Argo CD recognises them as its own.

Save your progress? Sign up for free

Drill 4: The project’s limits

Team Green tries to get more room in staging:

# on cp1
cd ~/cnpe/plattform
K=apps/team-green/shop/overlays/staging/kustomization.yaml
cat > apps/team-green/shop/overlays/staging/quota.yaml <<'EOF'
apiVersion: v1
kind: ResourceQuota
metadata:
  name: mehr-platz
spec:
  hard:
    requests.cpu: "50"
EOF
# add quota.yaml under resources, right after the base
sed -i 's#^- ../../base#- ../../base\n- quota.yaml#' $K
git add -A && git commit -qm 'staging: mehr Platz' && git push -q
argocd app get team-green-shop-staging --refresh >/dev/null
sleep 25
argocd app get team-green-shop-staging | grep -E 'Sync Status|ResourceQuota'
k -n argocd get application team-green-shop-staging -o jsonpath='{.status.operationState.phase}: {.status.operationState.message}{"\n"}'

Expected:

Sync Status:        OutOfSync from main (4456637)
       ResourceQuota  team-green-staging  mehr-platz   Unknown  Missing        resource :ResourceQuota is not permitted in project team-green
Running: one or more synchronization tasks are not valid: resource :ResourceQuota is not permitted in project team-green. Retrying attempt #2 at 2026-11-27T23:23:22Z.

The project blocks the entire sync, not just the quota. And the sync repeats with growing pauses – even after you have removed the quota from Git again. The running operation is stuck on the old revision and blocks every new sync. Try it:

# on cp1
git rm -q apps/team-green/shop/overlays/staging/quota.yaml
sed -i '/^- quota.yaml$/d' $K
git commit -qam 'staging: Quota wieder entfernt' && git push -q
# meanwhile, set staging to a new image
sed -i 's/newTag: "1.29"/newTag: "1.29-alpine"/' $K
git commit -qam 'staging: shop auf nginx 1.29-alpine' && git push -q
argocd app get team-green-shop-staging --refresh | grep -E 'Sync Status'
sleep 25
k -n team-green-staging get deploy shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'

Expected:

Sync Status:        OutOfSync from main (24a6bcd)
nginx:1.29

Git is correct, the cluster stays old. Solution: terminate the stuck operation.

# on cp1
argocd app terminate-op team-green-shop-staging
sleep 20
argocd app get team-green-shop-staging --refresh | grep -E 'Sync Status|Health Status'
k -n team-green-staging get deploy shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'

Expected:

Application 'team-green-shop-staging' operation terminating
Sync Status:        Synced to main (24a6bcd)
Health Status:      Healthy
nginx:1.29-alpine

Remember terminate-op: “Git is fixed, but nothing happens” is a typical exam trap.

Save your progress? Sign up for free

Drill 5: Promotion via pull request

1.29-alpine is running in staging. For prod the rule is: not directly on main, but via a branch and a pull request that someone reviews.

# on cp1
cd ~/cnpe/plattform
git switch -c promote-shop-prod
sed -i 's/newTag: "1.29"/newTag: "1.29-alpine"/' apps/team-green/shop/overlays/prod/kustomization.yaml
git commit -qam 'prod: shop auf nginx 1.29-alpine'
#   -u origin promote-shop-prod   create the branch on Gitea and link it
git push -q -u origin promote-shop-prod
# pull request via Gitea's API: head = branch with the change, base = target
curl -s -u platform:platform-lab-123 -H 'Content-Type: application/json' \
  -d '{"title":"shop: 1.29-alpine nach prod","head":"promote-shop-prod","base":"main","body":"Läuft seit heute in staging."}' \
  http://172.16.0.126:30300/api/v1/repos/platform/plattform/pulls \
  | jq -r '"PR #\(.number): \(.title) mergeable=\(.mergeable)"'
git diff main..promote-shop-prod --stat

Expected:

PR #1: shop: 1.29-alpine nach prod mergeable=true
 apps/team-green/shop/overlays/prod/kustomization.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Open the PR in Gitea (http://172.16.0.126:30300/platform/plattform/pulls/1): a one-line diff, exactly what goes to prod. Until the merge, prod stays unchanged – Argo CD follows main. You can click the merge in the UI or trigger it via the API:

# on cp1
#   Do: merge                      normal merge commit (alternatives: rebase, squash)
#   delete_branch_after_merge      delete the branch on Gitea afterwards
curl -s -o /dev/null -w '%{http_code}\n' -u platform:platform-lab-123 -H 'Content-Type: application/json' \
  -d '{"Do":"merge","delete_branch_after_merge":true}' \
  http://172.16.0.126:30300/api/v1/repos/platform/plattform/pulls/1/merge
argocd app get team-green-shop-prod --refresh >/dev/null
sleep 25
argocd app get team-green-shop-prod | grep -E 'Sync Status|Health Status'
k -n team-green get deploy shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
# clean up locally
git switch -q main && git pull -q && git branch -D promote-shop-prod
git log --oneline -3

Expected:

200
Sync Status:        Synced to main (6d99130)
Health Status:      Healthy
nginx:1.29-alpine
Deleted branch promote-shop-prod (was f123065).
6d99130 Merge pull request 'shop: 1.29-alpine nach prod' (#1) from promote-shop-prod into main
f123065 prod: shop auf nginx 1.29-alpine
24a6bcd staging: shop auf nginx 1.29-alpine

Save your progress? Sign up for free

Exercise: A new environment without touching Argo CD

Time limit: 5 minutes. Team Green briefly needs an environment test for shop. Create it without writing an Application – and remove it again afterwards.

Solution

# on cp1
cd ~/cnpe/plattform
O=apps/team-green/shop/overlays
# copy the overlay, adjust the namespace, push – the Git generator finds the directory
cp -r $O/staging $O/test
sed -i 's/team-green-staging/team-green-test/' $O/test/kustomization.yaml
git add -A && git commit -qm 'shop: Umgebung test' && git push -q
# generator (30 s) plus the repo-server's cache: wait a good minute
sleep 90
argocd app list -o name
k -n team-green-test get deploy shop

Expected:

argocd/team-green-shop-prod
argocd/team-green-shop-staging
argocd/team-green-shop-test
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
shop   1/1     1            1           58s
# on cp1
git rm -rq $O/test && git commit -qm 'shop: Umgebung test entfernt' && git push -q
sleep 120
argocd app list -o name
k -n team-green-test get all
k get ns team-green-test

Expected:

argocd/team-green-shop-prod
argocd/team-green-shop-staging
No resources found in team-green-test namespace.
NAME              STATUS   AGE
team-green-test   Active   3m4s

The Application is gone, and so are its objects – the namespace remains. CreateNamespace creates, but never deletes. To clean up: k delete ns team-green-test.

Save your progress? Sign up for free

Challenge

Time limit: 10 minutes. The namespaces the ApplicationSet creates (team-green-staging) have Team Green’s labels – but no quota, no LimitRange and no NetworkPolicies from Day 1. Why, and who should create them: the team, Argo CD or the platform?

Solution

The project forbids the team exactly these objects – rightly so, otherwise it would set its own limits. Argo CD could roll them out via a separate platform project, but would have to know every new namespace. The clean solution: the platform reacts to every new namespace with tier=tenant and creates the fences automatically – Kyverno generate on Day 9. Until then, you check for the gap like this:

# on cp1
# tenant namespaces without a ResourceQuota
for ns in $(k get ns -l tier=tenant -o name | cut -d/ -f2); do
  [ -z "$(k -n $ns get quota -o name)" ] && echo "$ns: keine Quota"
done

Expected:

team-green-staging: keine Quota

Save your progress? Sign up for free

Checkpoint

# on cp1
# two Applications from the ApplicationSet, both in the project team-green
k -n argocd get applications \
  -o custom-columns=NAME:.metadata.name,PROJECT:.spec.project,SYNC:.status.sync.status,HEALTH:.status.health.status
# both environments on 1.29-alpine
k -n team-green-staging get deploy shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
k -n team-green get deploy shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
# PR #1 is merged
curl -s -u platform:platform-lab-123 http://172.16.0.126:30300/api/v1/repos/platform/plattform/pulls/1 | jq .merged

Expected:

NAME                      PROJECT      SYNC     HEALTH
team-green-shop-prod      team-green   Synced   Healthy
team-green-shop-staging   team-green   Synced   Healthy
nginx:1.29-alpine
nginx:1.29-alpine
true

Interview Note

  • Why AppProjects when there is RBAC? RBAC governs what people do in the cluster. Argo CD applies with its own far-reaching permissions – the project limits what may end up in the cluster via Argo CD.
  • How do you promote with GitOps? By changing the state of the next environment in Git (image tag in the overlay), for prod via a pull request with review. No pipeline step with kubectl.
  • A sync is stuck even though Git is fixed – what do you do? Terminate the running operation with argocd app terminate-op; otherwise it keeps retrying the old revision.

Enterprise Note

  • Branch protection in Gitea for main: changes to overlays/prod only via PR with review (CODEOWNERS per team directory).
  • Manage the teams’ ApplicationSets themselves via GitOps (app of apps) and hard-wire project in the template – otherwise a team writes itself into other teams’ projects.
  • Webhook from Gitea to Argo CD and to the ApplicationSet controller instead of polling every 30 s.
  • Do not change the image tag by hand: Argo CD Image Updater or the CI (Day 6) write it via commit or PR.

Contents

More