Tag 2: Die erste Application
Ziel: notes-api kommt aus dem Fleet-Repo in den Cluster. Du siehst den Diff, synchronisierst von Hand und rollst eine Version zurück. · Dauer: ca. 45 min · Voraussetzung: Tag 1
Briefing
- Eine Application ist ein Kubernetes-Objekt im
Namespace
argocd. Sie verbindet eine Quelle (Repo, Revision, Pfad) mit einem Ziel (Cluster, Namespace). - Argo CD rendert die Quelle und vergleicht sie mit dem Ziel. Das
Ergebnis sind zwei Zustände: Sync (
SyncedoderOutOfSync) sagt, ob Git und Cluster gleich sind. Health (Healthy,Progressing,Degraded,Missing) sagt, ob die Objekte laufen. - Heute synchronisierst du von Hand. Ab Tag 3 macht Argo CD das selbst.
argocd-fleet/apps/notes ──► repo-server rendert ──► Soll
│ vergleichen
Namespace notes im Cluster ─────────────────────► Ist
▼
Synced/OutOfSync · Healthy/Missing/…
Drill 1: Die Manifeste ins Repo
Die Dateien aus Tag 0 kommen ins Fleet-Repo, diesmal ohne
Namespace-Objekt und ohne namespace: in den Metadaten. Den
Namespace bestimmt die Application.
cd ~/argo-lab/argocd-fleet
mkdir -p apps/notes
cat > apps/notes/secret.yaml <<'EOF'
apiVersion: v1
kind: Secret
metadata:
name: notes-api
stringData:
apiKey: lab-api-key-123
EOF
cat > apps/notes/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: notes
spec:
replicas: 1
selector:
matchLabels:
app: notes
template:
metadata:
labels:
app: notes
spec:
containers:
- name: api
image: ghcr.io/thomaszachmann/notes-api:0.5.1
ports:
- containerPort: 8080
env:
- name: NOTES_API_KEY
valueFrom:
secretKeyRef:
name: notes-api
key: apiKey
readinessProbe:
httpGet:
path: /healthz
port: 8080
EOF
cat > apps/notes/service.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: notes
spec:
type: NodePort
selector:
app: notes
ports:
- port: 80
targetPort: 8080
nodePort: 30080
EOFDer API-Key steht im Klartext in Git. So darf es nicht bleiben, Tag 10 räumt das auf.
git add .
git commit -m "notes-api 0.5.1"
git push -u origin mainErwartet (gekürzt):
[main (root-commit) 6135e30] notes-api 0.5.1
3 files changed, 47 insertions(+)
…
branch 'main' set up to track 'origin/main'.
Fortschritt speichern? Kostenlos registrieren
Drill 2: Das Repo bei Argo CD anmelden
Das Repo ist privat. Argo CD braucht denselben Deploy-Key wie du:
argocd repo add [email protected]:<du>/argocd-fleet.git \
--ssh-private-key-path ~/.ssh/argocd-fleet
argocd repo listErwartet:
Repository '[email protected]:<du>/argocd-fleet.git' added
TYPE NAME REPO INSECURE OCI LFS CREDS STATUS MESSAGE PROJECT
git [email protected]:<du>/argocd-fleet.git false false false false Successful
Successful heißt: Argo CD hat sich mit dem Schlüssel
verbunden und das Repo gelesen. Den Host-Key von GitHub kennt Argo CD
schon aus argocd-ssh-known-hosts-cm.
Gespeichert wird das Repo als Secret mit einem besonderen Label:
kubectl -n argocd get secret -l argocd.argoproj.io/secret-type=repositoryErwartet (Name weicht ab):
NAME TYPE DATA AGE
repo-3993372767 Opaque 3 2s
Fortschritt speichern? Kostenlos registrieren
Drill 3: Die Application
Du schreibst die Application als Datei. Sie liegt heute noch außerhalb des Fleet-Repos, an Tag 7 zieht sie dort ein.
mkdir -p ~/argo-lab/tag02
cd ~/argo-lab/tag02
cat > notes-app.yaml <<'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: notes
namespace: argocd
spec:
project: default
source:
repoURL: [email protected]:<du>/argocd-fleet.git
targetRevision: main
path: apps/notes
destination:
server: https://kubernetes.default.svc
namespace: notes
syncPolicy:
syncOptions:
- CreateNamespace=true
EOF
kubectl apply -f notes-app.yamlErwartet:
application.argoproj.io/notes created
project: defaultist das Projekt, das jede Installation mitbringt. Es erlaubt alles. Eigene Projekte mit Grenzen kommen an Tag 9.targetRevision: mainfolgt dem Branch. Ein Tag oder ein Commit-Hash ginge auch.CreateNamespace=truelegtnotesan, falls es fehlt.
argocd app get notesErwartet (gekürzt):
Name: argocd/notes
Project: default
Server: https://kubernetes.default.svc
Namespace: notes
URL: https://172.16.0.182:30443/applications/notes
…
Sync Policy: Manual
Sync Status: OutOfSync from main (6135e30)
Health Status: Missing
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
Secret notes notes-api OutOfSync Missing
Service notes notes OutOfSync Missing
apps Deployment notes notes OutOfSync Missing
Argo CD hat das Repo gelesen und weiß, was fehlt. Angelegt hat es
noch nichts, denn die Sync-Policy ist Manual.
Fortschritt speichern? Kostenlos registrieren
Drill 4: Diff und Sync
argocd app diff notesErwartet (gekürzt):
===== /Secret notes/notes-api ======
0a1,9
> apiVersion: v1
> data:
> apiKey: ++++++++
> kind: Secret
> metadata:
> annotations:
> argocd.argoproj.io/tracking-id: notes:/Secret:notes/notes-api
…
- Den Wert des Secrets zeigt Argo CD nie, nur
++++++++. - Die Annotation
argocd.argoproj.io/tracking-idsetzt Argo CD an jedes Objekt. Daran erkennt es später, welche Objekte zu welcher Application gehören.
argocd app sync notesErwartet (gekürzt):
…
Phase: Succeeded
…
Message: successfully synced (all tasks run)
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
Namespace notes Running Synced namespace/notes created
Secret notes notes-api Synced secret/notes-api created
Service notes notes Synced Healthy service/notes created
apps Deployment notes notes Synced Healthy deployment.apps/notes created
argocd app list
curl -s localhost:30080/versionErwartet (gekürzt):
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY …
argocd/notes https://kubernetes.default.svc notes default Synced Healthy Manual …
0.5.1
Im Browser siehst du dasselbe als Baum: Application, darunter Deployment, ReplicaSet und Pod.
Fortschritt speichern? Kostenlos registrieren
Drill 5: Eine Änderung über Git
Die neue Version kommt jetzt nicht mehr per
kubectl set image, sondern per Commit:
cd ~/argo-lab/argocd-fleet
sed -i "s/notes-api:0.5.1/notes-api:0.5.3/" apps/notes/deployment.yaml
git commit -am "notes-api 0.5.3"
git pushErwartet (gekürzt):
[main 23d84d9] notes-api 0.5.3
1 file changed, 1 insertion(+), 1 deletion(-)
Argo CD fragt Git von sich aus alle 120 Sekunden ab, plus eine kleine
Zufallsverzögerung. Mit --refresh musst du nicht
warten:
argocd app get notes --refresh | grep -E "Sync Status|Health Status"
argocd app diff notesErwartet:
Sync Status: OutOfSync from main (23d84d9)
Health Status: Healthy
===== apps/Deployment notes/notes ======
141c141
< image: ghcr.io/thomaszachmann/notes-api:0.5.1
---
> image: ghcr.io/thomaszachmann/notes-api:0.5.3
Health bleibt Healthy, denn es läuft ja weiter eine
Version. Nur Git und Cluster passen nicht mehr zusammen.
argocd app sync notes
argocd app wait notes --health
curl -s localhost:30080/versionErwartet (gekürzt):
…
0.5.3
Fortschritt speichern? Kostenlos registrieren
Drill 6: Verlauf und Rollback
argocd app history notesErwartet:
SOURCE [email protected]:<du>/argocd-fleet.git
ID DATE REVISION
0 2026-11-14 08:28:44 +0000 UTC main (6135e30)
1 2026-11-14 08:29:05 +0000 UTC main (23d84d9)
Jeder Sync steht hier mit seinem Commit. Ein Rollback synchronisiert einen alten Eintrag:
argocd app rollback notes 0
curl -s localhost:30080/version
argocd app get notes | grep -E "Sync Status|Health Status"Erwartet (gekürzt):
…
Message: successfully synced (all tasks run)
…
apps Deployment notes notes OutOfSync Healthy deployment.apps/notes configured
0.5.1
Sync Status: OutOfSync from main (23d84d9)
Health Status: Healthy
Der Cluster läuft wieder mit 0.5.1, aber Git sagt weiter 0.5.3. Ein Rollback ist eine Notbremse, keine Lösung. Die eigentliche Korrektur ist ein Commit. Für heute holst du den Stand aus Git zurück:
argocd app sync notes
argocd app get notes | grep -E "Sync Status|Health Status"Erwartet (gekürzt):
…
Sync Status: Synced to main (23d84d9)
Health Status: Healthy
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
argocd app listErwartet: argocd/notes mit Synced und
Healthy.
curl -s localhost:30080/versionErwartet: 0.5.3.
kubectl -n notes get deploy notes -o yaml | grep tracking-idErwartet: zwei Zeilen, die erste lautet
argocd.argoproj.io/tracking-id: notes:apps/Deployment:notes/notes.
Challenge
notes-api soll mit zwei Pods laufen. Ändere das nur über Git und synchronisiere.
Hinweis: replicas im Deployment, dann
commit, push, --refresh,
sync.
Lösung
cd ~/argo-lab/argocd-fleet
sed -i "s/replicas: 1/replicas: 2/" apps/notes/deployment.yaml
git commit -am "notes: zwei Replikate"
git push
argocd app get notes --refresh
argocd app sync notes
argocd app wait notes --health
kubectl -n notes get deploy notesErwartet (gekürzt):
NAME READY UP-TO-DATE AVAILABLE AGE
notes 2/2 2 2 75s
Fortschritt speichern? Kostenlos registrieren
Enterprise-Notiz
- Applications gehören selbst ins Git, nicht in einzelne Dateien auf einem Laptop. Tag 7 zeigt das Muster dafür.
- Statt alle drei Minuten zu fragen, kann GitHub per Webhook Bescheid
geben (
/api/webhookam argocd-server). Das spart Wartezeit und Last. targetRevisionauf einen Tag oder Commit festzunageln ist für Produktion üblich. Ein Release ist dann ein Commit, der diese Zeile ändert.