Tag 4: Argo CD für Teams – Projekte, ApplicationSets, Promotion
Ziel: Team Green bekommt ein eigenes Argo-CD-Projekt mit Grenzen, Umgebungen als Kustomize-Overlays, ein ApplicationSet, das für jede Umgebung selbst eine Application erzeugt, und einen Weg nach Produktion über einen Pull Request · Dauer: ca. 75 min · Voraussetzung: Tag 3
Briefing
- Eine Application von Hand pro Dienst und Umgebung skaliert nicht. Eine Plattform braucht drei Dinge:
| Baustein | Aufgabe |
|---|---|
| AppProject | Grenzen eines Teams: welche Repos, welche Ziel-Namespaces, welche Ressourcen |
| Kustomize-Overlays | eine Basis, pro Umgebung nur die Unterschiede |
| ApplicationSet | erzeugt Applications aus einer Vorlage und einem Generator |
- Promotion heißt: eine Version, die in staging läuft, nach prod bringen. Bei GitOps ist das eine Änderung in Git – und für prod eine, die jemand prüft: ein Pull Request.
- Generatoren, die du kennen solltest: list (feste Liste), git (Verzeichnisse oder Dateien im Repo), cluster (registrierte Cluster), matrix/merge (Kombinationen). Heute nutzt du den Git-Generator: Ein neues Verzeichnis im Repo wird eine neue Application.
Drill 1: Eine Basis, zwei Umgebungen
Die Application team-green-shop von Tag 3 löschst du,
ohne ihre Objekte mitzunehmen – das ApplicationSet übernimmt sie
gleich:
# auf cp1
# --cascade=orphan nur die Application löschen, Deployment, Service, ConfigMap bleiben
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
# bisherige Manifeste werden die Basis; die Migration von Tag 3 entfällt
git mv $S/deployment.yaml $S/service.yaml $S/config.yaml $S/base/
git rm -q $S/migration.yaml
# Namespace aus der Basis entfernen – den setzt jede Umgebung selbst
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 # alle Objekte in diesen Namespace
resources:
- ../../base
replicas: # Kopienzahl je Umgebung
- name: shop
count: 1
images: # Image-Tag je Umgebung – hier findet die Promotion statt
- 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
# so sieht staging gerendert aus
k kustomize $S/overlays/staging | grep -E 'namespace:|replicas:|image:'
git add -A && git commit -qm 'shop: Kustomize mit staging und prod' && git push -qErwartet:
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
Fortschritt speichern? Kostenlos registrieren
Drill 2: Das Projekt von Team Green
Das Projekt default erlaubt alles. Team Green bekommt
eigene Grenzen:
# auf 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: # nur aus diesem Repo
- http://172.16.0.126:30300/platform/plattform.git
destinations: # nur in diese Namespaces (Platzhalter * erlaubt)
- server: https://kubernetes.default.svc
namespace: team-green
- server: https://kubernetes.default.svc
namespace: team-green-*
clusterResourceWhitelist: # clusterweite Objekte: nur Namespaces (für CreateNamespace)
- group: ""
kind: Namespace
namespaceResourceBlacklist: # die Zäune von Tag 1 darf das Team nicht anfassen
- group: ""
kind: ResourceQuota
- group: ""
kind: LimitRange
- group: networking.k8s.io
kind: NetworkPolicy
EOF
k apply -f projekt-team-green.yaml
argocd proj get team-greenErwartet (gekürzt):
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
Fortschritt speichern? Kostenlos registrieren
Drill 3: Das ApplicationSet
Der Git-Generator findet jedes Verzeichnis
apps/team-green/<dienst>/overlays/<umgebung>.
Für jedes erzeugt die Vorlage eine Application.
# auf cp1
cat > appset-team-green.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: team-green
namespace: argocd
spec:
goTemplate: true # Vorlagen in Go-Template-Syntax
goTemplateOptions: ["missingkey=error"] # Tippfehler in Variablen = Fehler statt leerer Text
generators:
- git:
repoURL: http://172.16.0.126:30300/platform/plattform.git
revision: main
requeueAfterSeconds: 30 # Repo alle 30 s prüfen (Standard: 180 s)
directories:
- path: apps/team-green/*/overlays/*
template:
metadata:
# path.segments: [apps, team-green, shop, overlays, staging] → Index 2 = Dienst
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, alles andere → team-green-<umgebung>
namespace: '{{ if eq .path.basename "prod" }}team-green{{ else }}team-green-{{ .path.basename }}{{ end }}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true # fehlenden Namespace anlegen ...
managedNamespaceMetadata: # ... mit diesen Labels
labels:
team: green
tier: tenant
EOF
k apply -f appset-team-green.yaml
sleep 45
argocd app list
k get ns -l team=greenErwartet (gekürzt):
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
Zwei Stolpersteine, die beim Bauen dieses ApplicationSets wirklich auftraten:
- Ohne
destination.namespaceerzeugt das ApplicationSet die Applications, aber sie bleibenUnknownmitInvalidSpecError: namespace ’’ do not match any of the allowed destinations in project ‘team-green’. Das Projekt erlaubt nur benannte Namespaces – „kein Namespace“ gehört nicht dazu. Die Meldung steht ink -n argocd get application <name> -o jsonpath='{.status.conditions}'. - Doppelte Anführungszeichen im Template brauchen
außen einfache:
namespace: '{{ if eq … "prod" }}…'. Mit doppelten außen bricht der YAML-Parser ab (did not find expected key).
team-green-shop-prod hat die verwaisten Objekte von Tag
3 übernommen: gleicher Name, gleicher Namespace – Argo CD erkennt sie
als seine.
Fortschritt speichern? Kostenlos registrieren
Drill 4: Die Grenzen des Projekts
Team Green versucht, sich in staging mehr Platz zu verschaffen:
# auf 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
# quota.yaml unter resources eintragen, direkt nach der Basis
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"}'Erwartet:
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.
Das Projekt blockiert den ganzen Sync, nicht nur die Quota. Und der Sync wiederholt sich mit wachsender Pause – auch nachdem du die Quota wieder aus Git entfernt hast. Der laufende Vorgang hängt an der alten Revision und blockiert jeden neuen Sync. Probier es:
# auf 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
# staging schon mal auf ein neues Image setzen
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"}'Erwartet:
Sync Status: OutOfSync from main (24a6bcd)
nginx:1.29
Git ist richtig, der Cluster bleibt alt. Lösung: den hängenden Vorgang beenden.
# auf 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"}'Erwartet:
Application 'team-green-shop-staging' operation terminating
Sync Status: Synced to main (24a6bcd)
Health Status: Healthy
nginx:1.29-alpine
Merke dir terminate-op: „Git ist korrigiert, aber nichts
passiert“ ist eine typische Prüfungsfalle.
Fortschritt speichern? Kostenlos registrieren
Drill 5: Promotion per Pull Request
1.29-alpine läuft in staging. Für prod gilt: nicht
direkt auf main, sondern über einen Branch und einen Pull
Request, den jemand prüft.
# auf 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 Branch auf Gitea anlegen und verknüpfen
git push -q -u origin promote-shop-prod
# Pull Request über die API von Gitea: head = Branch mit der Änderung, base = Ziel
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 --statErwartet:
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(-)
Öffne den PR in Gitea
(http://172.16.0.126:30300/platform/plattform/pulls/1):
eine Zeile Diff, genau das, was nach prod geht. Bis zum Merge bleibt
prod unverändert – Argo CD folgt main. Den Merge kannst du
in der Oberfläche klicken oder über die API auslösen:
# auf cp1
# Do: merge normaler Merge-Commit (Alternativen: rebase, squash)
# delete_branch_after_merge Branch auf Gitea danach löschen
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"}'
# lokal aufräumen
git switch -q main && git pull -q && git branch -D promote-shop-prod
git log --oneline -3Erwartet:
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
Fortschritt speichern? Kostenlos registrieren
Übung: Eine neue Umgebung ohne Argo CD anzufassen
Zeitvorgabe: 5 Minuten. Team Green braucht kurz eine Umgebung
test für shop. Lege sie an, ohne eine
Application zu schreiben – und entferne sie danach wieder.
Lösung
# auf cp1
cd ~/cnpe/plattform
O=apps/team-green/shop/overlays
# Overlay kopieren, Namespace anpassen, pushen – der Git-Generator findet das Verzeichnis
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 Cache des repo-servers: gut eine Minute warten
sleep 90
argocd app list -o name
k -n team-green-test get deploy shopErwartet:
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
# auf 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-testErwartet:
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
Die Application ist weg, ihre Objekte auch – der Namespace
bleibt. CreateNamespace legt an, löscht aber nie.
Aufräumen: k delete ns team-green-test.
Fortschritt speichern? Kostenlos registrieren
Challenge
Zeitvorgabe: 10 Minuten. Die Namespaces, die das ApplicationSet
anlegt (team-green-staging), haben die Labels von Team
Green – aber keine Quota, keine LimitRange und keine NetworkPolicies von
Tag 1. Warum, und wer sollte sie anlegen: das Team, Argo CD oder die
Plattform?
Lösung
Das Projekt verbietet dem Team genau diese Objekte – zu Recht, sonst
setzt es sich selbst die Grenzen. Argo CD könnte sie über ein eigenes
Projekt der Plattform ausrollen, müsste aber jeden neuen Namespace
kennen. Die saubere Lösung: Die Plattform reagiert auf
jeden neuen Namespace mit tier=tenant und
legt die Zäune automatisch an – Kyverno generate an Tag 9.
Bis dahin prüfst du die Lücke so:
# auf cp1
# Mandanten-Namespaces ohne 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"
doneErwartet:
team-green-staging: keine Quota
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
# auf cp1
# zwei Applications aus dem ApplicationSet, beide im Projekt team-green
k -n argocd get applications \
-o custom-columns=NAME:.metadata.name,PROJECT:.spec.project,SYNC:.status.sync.status,HEALTH:.status.health.status
# beide Umgebungen auf 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 ist gemergt
curl -s -u platform:platform-lab-123 http://172.16.0.126:30300/api/v1/repos/platform/plattform/pulls/1 | jq .mergedErwartet:
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-Notiz
- Wozu AppProjects, wenn es RBAC gibt? RBAC regelt, was Menschen im Cluster tun. Argo CD wendet mit eigenen, weitreichenden Rechten an – das Projekt begrenzt, was über Argo CD im Cluster landen darf.
- Wie promotest du bei GitOps? Indem du in Git den Stand der
nächsten Umgebung änderst (Image-Tag im Overlay), für prod per Pull
Request mit Review. Kein Pipeline-Schritt mit
kubectl. - Ein Sync hängt, obwohl Git korrigiert ist – was tust du?
Den laufenden Vorgang mit
argocd app terminate-opbeenden; er wiederholt sonst die alte Revision.
Enterprise-Notiz
- Branch-Schutz in Gitea für
main: Änderungen anoverlays/prodnur per PR mit Review (CODEOWNERS je Team-Verzeichnis). - ApplicationSets der Teams selbst per GitOps verwalten (App of Apps)
und
projectim Template fest verdrahten – sonst schreibt ein Team sich in fremde Projekte. - Webhook von Gitea an Argo CD und an den ApplicationSet-Controller, statt alle 30 s zu fragen.
- Den Image-Tag nicht von Hand ändern: Argo CD Image Updater oder die CI (Tag 6) schreiben ihn per Commit oder PR.