Tag 7: App of Apps
Ziel: Alle Applications liegen im Fleet-Repo. Eine einzige Application
rootverwaltet sie, und nurrootlegst du noch von Hand an. · Dauer: ca. 40 min · Voraussetzung: Tag 6
Briefing
- Bisher liegen die Applications als Dateien in
~/argo-lab/tagNN. Ein Laptop weg, und niemand weiß mehr, wie Argo CD eingerichtet war. - Eine Application ist ein Kubernetes-Objekt wie jedes andere. Eine Application kann also andere Applications verwalten. Dieses Muster heißt App of Apps.
- Die äußere Application heißt hier
root. Sie zeigt auf den Ordnerapplications, in dem die übrigen Applications liegen. - Mit dem Finalizer
resources-finalizer.argocd.argoproj.iolöscht Argo CD beim Entfernen einer Application auch deren Objekte.
bootstrap/root.yaml (einmal von Hand: kubectl apply)
│
▼
Application root ──► applications/
├─ notes.yaml ─► Application notes ─► ns notes
├─ notes-dev.yaml ─► Application notes-dev ─► ns notes-dev
└─ podinfo.yaml ─► Application podinfo ─► ns podinfo
Drill 1: Applications ins Repo
Die Dateien aus Tag 5 und 6 kommen ins Fleet-Repo, unverändert:
cd ~/argo-lab/argocd-fleet
mkdir -p applications bootstrap
cp ~/argo-lab/tag06/notes-app.yaml applications/notes.yaml
cp ~/argo-lab/tag06/notes-dev-app.yaml applications/notes-dev.yaml
cp ~/argo-lab/tag05/podinfo-app.yaml applications/podinfo.yamlDazu root. Sie zielt auf den Namespace
argocd, denn dort leben Applications:
cat > bootstrap/root.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: root
namespace: argocd
spec:
project: default
source:
repoURL: [email protected]:<du>/argocd-fleet.git
targetRevision: main
path: applications
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated:
selfHeal: true
prune: true
EOF
git add -A
git commit -m "App of Apps"
git pushroot.yaml liegt in bootstrap, nicht in
applications. Sonst würde root sich selbst
verwalten, und ein falscher Commit könnte sie löschen.
Fortschritt speichern? Kostenlos registrieren
Drill 2: root anlegen
Das ist das letzte kubectl apply für eine
Application:
kubectl apply -f bootstrap/root.yaml
argocd app wait root --health --syncErwartet (gekürzt):
application.argoproj.io/root created
…
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
argoproj.io Application argocd notes Synced application.argoproj.io/notes configured
argoproj.io Application argocd notes-dev Synced application.argoproj.io/notes-dev configured
argoproj.io Application argocd podinfo Synced application.argoproj.io/podinfo configured
Die drei Applications gab es schon. root hat sie
übernommen, nicht neu angelegt. Nichts in den Namespaces
notes, notes-dev und podinfo
wurde angefasst.
Die Spalte HEALTH bleibt bei den Applications leer. Für
Objekte vom Typ Application bringt Argo CD keine Health-Regel mit.
root ist also Healthy, auch wenn eines ihrer
Kinder Degraded ist. Wer das anders will, ergänzt eine
Health-Regel in argocd-cm.
argocd app list -o nameErwartet:
argocd/notes
argocd/notes-dev
argocd/podinfo
argocd/root
Fortschritt speichern? Kostenlos registrieren
Drill 3: Die Falle aus Tag 5
Jetzt, wo root die Applications mit Self-Heal verwaltet,
müsste ein argocd app set doch zurückgedreht werden?
argocd app set podinfo --source-position 1 -p replicaCount=3
sleep 60
argocd app get root | grep "Sync Status"
kubectl -n argocd get app podinfo -o jsonpath='{.spec.sources[0].helm}'
kubectl -n podinfo get deploy podinfoErwartet:
Sync Status: Synced to main (b2c8d21)
{"parameters":[{"name":"replicaCount","value":"3"}],"valueFiles":["$fleet/values/podinfo.yaml"]}
NAME READY UP-TO-DATE AVAILABLE AGE
podinfo 3/3 3 3 17m
Ausprobiert:
rootbleibtSynced, und podinfo läuft mit drei Pods. Das Feldparameterssteht nicht inapplications/podinfo.yaml. Für den Vergleich zählt es deshalb nicht, genau wie das Label in Tag 3. Self-Heal schützt nur, was in Git steht. Was jemand zusätzlich setzt, bleibt unbemerkt.
Du räumst es von Hand ab:
argocd app unset podinfo --source-position 1 -p replicaCountFortschritt speichern? Kostenlos registrieren
Drill 4: Eine Application entfernen
podinfo hat seinen Zweck erfüllt. Damit beim Entfernen auch Deployment und Service verschwinden, bekommt die Application zuerst den Finalizer. Die ganze Datei:
cat > applications/podinfo.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: podinfo
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
sources:
- repoURL: https://stefanprodan.github.io/podinfo
chart: podinfo
targetRevision: 6.17.0
helm:
valueFiles:
- $fleet/values/podinfo.yaml
- repoURL: [email protected]:<du>/argocd-fleet.git
targetRevision: main
ref: fleet
destination:
server: https://kubernetes.default.svc
namespace: podinfo
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
EOF
git commit -am "podinfo: Finalizer"
git push
argocd app get root --refresh
kubectl -n argocd get app podinfo -o jsonpath='{.metadata.finalizers}'Erwartet (gekürzt):
["resources-finalizer.argocd.argoproj.io"]
Erst wenn der Finalizer im Cluster steht, löschst du die Datei:
git rm applications/podinfo.yaml
git commit -m "podinfo entfernt"
git push
argocd app get root --refresh
sleep 25
argocd app list -o name
kubectl -n podinfo get all
kubectl get ns podinfoErwartet:
argocd/notes
argocd/notes-dev
argocd/root
No resources found in podinfo namespace.
NAME STATUS AGE
podinfo Active 18m
root hat die Application per prune
gelöscht. Der Finalizer hat dafür gesorgt, dass Argo CD vorher
Deployment und Service entfernt. Der Namespace bleibt stehen, denn
CreateNamespace=true legt ihn nur an, er gehört der
Application nicht. Du räumst ihn von Hand ab:
kubectl delete ns podinfoErwartet:
namespace "podinfo" deleted
Für notes und notes-dev setzt du den
Finalizer bewusst nicht. Ein falscher Commit in
applications soll keine Datenbank löschen können.
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
argocd app get root | grep -E "Sync Status|Health Status"Erwartet: Synced und Healthy.
ls ~/argo-lab/argocd-fleet/applicationsErwartet: notes-dev.yaml notes.yaml.
argocd app get root -o treeErwartet (gekürzt):
KIND/NAME STATUS HEALTH MESSAGE
Application/notes Synced application.argoproj.io/notes unchanged
Application/notes-dev Synced application.argoproj.io/notes-dev unchanged
Challenge
Der NodePort-Service für die Weboberfläche aus Tag 1 ist noch eine
Datei auf deiner VM. Lass ihn von Argo CD verwalten: eine neue
Application argocd-extras für den Ordner
platform/argocd im Fleet-Repo, angelegt nur über Git.
Hinweis: Ziel-Namespace ist argocd. Die
Datei aus ~/argo-lab/tag01 kannst du übernehmen.
Lösung
cd ~/argo-lab/argocd-fleet
mkdir -p platform/argocd
cp ~/argo-lab/tag01/argocd-nodeport.yaml platform/argocd/
cat > applications/argocd-extras.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argocd-extras
namespace: argocd
spec:
project: default
source:
repoURL: [email protected]:<du>/argocd-fleet.git
targetRevision: main
path: platform/argocd
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated:
selfHeal: true
prune: true
EOF
git add -A
git commit -m "argocd-extras"
git push
argocd app get root --refresh
sleep 20
argocd app get argocd-extrasErwartet (gekürzt):
Sync Status: Synced to main (e52273d)
Health Status: Healthy
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
Service argocd argocd-server-nodeport Synced Healthy service/argocd-server-nodeport configured
configured statt created: Den Service gab
es schon, Argo CD hat ihn übernommen. Argo CD verwaltet damit ein Stück
von sich selbst. Löschst du den Service aus Versehen mit
kubectl, legt Self-Heal ihn wieder an.
Fortschritt speichern? Kostenlos registrieren
Enterprise-Notiz
- Im Betrieb liegt auch Argo CD selbst im Fleet-Repo, meist als
Helm-Chart mit Werten. Nach dem ersten
helm installübernimmt eine Application den Rest. bootstrap/enthält alles, was ein neuer Cluster einmal von Hand braucht: Argo CD undroot. Ein Wiederaufbau dauert damit Minuten.- Statt einer Datei pro Application erzeugen ApplicationSets viele gleichartige auf einmal. Das zeigt Tag 8.