Appendix B: Final Exam
Goal: Four exercises without instructions that tie together everything from the book. · Duration: approx. 60 min · Prerequisite: Days 0–15
Rules of Play
- You work in the VM
argoin the fleet repo~/argo-lab/argocd-fleet. Everything that changes the cluster goes through Git. The only exceptions are users inargocd-cmand passwords. - Each exercise has check commands. The exercise is solved only once they show what is listed there.
- The solutions are also in
~/argo-lab/code/loesung/pruefung/.
cd ~/argo-lab/argocd-fleet
git pullExercise 1: A staging Environment
notes gets an environment staging in the namespace
notes-staging on NodePort 30088. It runs
notes-api 0.7.0, regardless of what base says.
You do not create an Application, only a folder.
Check:
curl -s localhost:30088/version; echo
argocd app get notes-staging | grep -E "^Project|Sync Status|Health Status"Expected (abridged):
0.7.0
Project: notes
Sync Status: Synced to main (25dc551)
Health Status: Healthy
Solution
mkdir -p apps/notes/overlays/staging
cat > apps/notes/overlays/staging/env.yaml <<'EOF'
name: notes-staging
namespace: notes-staging
EOF
cat > apps/notes/overlays/staging/kustomization.yaml <<'EOF'
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
images:
- name: ghcr.io/thomaszachmann/notes-api
newTag: 0.7.0
patches:
- path: nodeport.yaml
EOF
cat > apps/notes/overlays/staging/nodeport.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: notes
spec:
ports:
- port: 80
targetPort: 8080
nodePort: 30088
EOF
git add -A
git commit -m "Umgebung staging"
git push
kubectl -n argocd annotate appset notes \
argocd.argoproj.io/application-set-refresh=true --overwrite
sleep 15
argocd app wait notes-staging --health --operation --timeout 300 | grep "^Phase"Expected (abridged):
…
Phase: Succeeded
The ApplicationSet from Day 8 generates the Application, the project
from Day 9 allows notes-staging, and images
from Day 6 sets the version.
Save your progress? Sign up for free
Exercise 2: A Read-Only User
Create a local user bob with the password
lab-bob-pw-123. bob sees all Applications in the
notes project, but may not sync anything. The rule lives in
Git.
Check:
argocd login 172.16.0.182:30443 --username bob --password lab-bob-pw-123 \
--insecure --name bob
argocd account can-i get applications "notes/*"
argocd account can-i sync applications "notes/*"
argocd app list -o name
argocd context 172.16.0.182:30443Expected:
'bob:login' logged in successfully
Context 'bob' updated
yes
no
argocd/notes
argocd/notes-dev
argocd/notes-rollout
argocd/notes-staging
Switched to context '172.16.0.182:30443'
Solution
kubectl -n argocd patch cm argocd-cm --type merge \
-p '{"data":{"accounts.bob":"login"}}'
argocd account update-password --account bob \
--current-password lab-argo-pw-123 --new-password lab-bob-pw-123
cat >> platform/argocd/argocd-rbac-cm.yaml <<'EOF'
p, role:notes-leser, applications, get, notes/*, allow
g, bob, role:notes-leser
EOF
tail -6 platform/argocd/argocd-rbac-cm.yaml
git commit -am "RBAC: bob liest notes"
git push
argocd app get argocd-extras --refresh
sleep 15Expected (abridged):
configmap/argocd-cm patched
Password updated
policy.csv: |
p, role:notes-entwickler, applications, get, notes/*, allow
p, role:notes-entwickler, applications, sync, notes/notes-dev, allow
g, alice, role:notes-entwickler
p, role:notes-leser, applications, get, notes/*, allow
g, bob, role:notes-leser
…
The new lines need the same indentation as the old ones, otherwise
they no longer belong to policy.csv.
Save your progress? Sign up for free
Exercise 3: An Addon for All Clusters
On every cluster with a stufe label, there should be a
ConfigMap hallo in the namespace hallo with
the entry gruss: Hallo aus dem Fleet-Repo. Do not change
any ApplicationSet or Application for this.
Check:
argocd app list -o name | grep hallo
kubectl --kubeconfig ~/.kube/prod.yaml -n hallo get cm hallo \
-o jsonpath='{.data.gruss}'; echo
kubectl -n hallo get cm hallo -o jsonpath='{.data.gruss}'; echoExpected:
argocd/hallo-in-cluster
argocd/hallo-prod
Hallo aus dem Fleet-Repo
Hallo aus dem Fleet-Repo
Solution
mkdir -p addons/hallo
cat > addons/hallo/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: hallo
data:
gruss: Hallo aus dem Fleet-Repo
EOF
git add -A
git commit -m "Addon hallo"
git push
kubectl -n argocd annotate appset addons \
argocd.argoproj.io/application-set-refresh=true --overwrite
sleep 30The matrix generator from Day 11 combines every folder under
addons with every cluster that has a stufe
label. A new folder is enough.
Save your progress? Sign up for free
Exercise 4: staging Follows the 0.7 Line
The Image Updater should also watch notes-staging, with
the same constraint as for notes and
notes-dev. Afterwards, Git contains a new version for
staging without you having entered it.
Check (after about three minutes):
git pull
git log -1 --format="%an: %s"
grep newTag apps/notes/overlays/staging/kustomization.yaml
curl -s localhost:30088/version; echo
kubectl -n argocd get imageupdater notesExpected (abridged):
…
argocd-image-updater: build: automatic update of notes-staging
newTag: 0.7.1
0.7.1
NAME APPS IMAGES LAST CHECKED READY
notes 3 3 56s True
Solution
applicationRefs is the last block in
applications/notes-updater.yaml. You append a third
entry:
cat >> applications/notes-updater.yaml <<'EOF'
- namePattern: notes-staging
images:
- alias: api
imageName: ghcr.io/thomaszachmann/notes-api:~0.7
EOF
git commit -am "ImageUpdater auch für notes-staging"
git push
argocd app get root --refresh
sleep 150In staging’s kustomization.yaml, the Image Updater
replaces 0.7.0 with 0.7.1, just like
kustomize edit set image. The fixed tag from Exercise 1 was
therefore only the starting point.
Save your progress? Sign up for free
Cleanup
staging, the addon, and bob go away again. The two files you appended something to, you rewrite completely:
cd ~/argo-lab/argocd-fleet
git pull
git rm -r apps/notes/overlays/staging addons/hallo
cat > applications/notes-updater.yaml <<'EOF'
apiVersion: argocd-image-updater.argoproj.io/v1alpha1
kind: ImageUpdater
metadata:
name: notes
namespace: argocd
spec:
writeBackConfig:
method: git
gitConfig:
branch: main
writeBackTarget: kustomization
applicationRefs:
- namePattern: notes
images:
- alias: api
imageName: ghcr.io/thomaszachmann/notes-api:~0.7
- namePattern: notes-dev
images:
- alias: api
imageName: ghcr.io/thomaszachmann/notes-api:~0.7
EOF
cat > platform/argocd/argocd-rbac-cm.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-rbac-cm
namespace: argocd
labels:
app.kubernetes.io/name: argocd-rbac-cm
app.kubernetes.io/part-of: argocd
data:
policy.csv: |
p, role:notes-entwickler, applications, get, notes/*, allow
p, role:notes-entwickler, applications, sync, notes/notes-dev, allow
g, alice, role:notes-entwickler
EOF
git commit -am "Prüfung aufgeräumt"
git push
kubectl -n argocd patch cm argocd-cm --type json \
-p '[{"op":"remove","path":"/data/accounts.bob"}]'
argocd app get root --refresh
argocd app get argocd-extras --refresh
kubectl -n argocd annotate appset notes \
argocd.argoproj.io/application-set-refresh=true --overwrite
kubectl -n argocd annotate appset addons \
argocd.argoproj.io/application-set-refresh=true --overwrite
sleep 30
kubectl delete ns notes-staging hallo
kubectl --kubeconfig ~/.kube/prod.yaml delete ns hallo
argocd app list | awk 'NR>1 {print $5, $6}' | sort | uniq -cExpected (abridged):
…
namespace "notes-staging" deleted
namespace "hallo" deleted
namespace "hallo" deleted
11 Synced Healthy
notes-stagingstays after the folder is removed, because ofpreserveResourcesOnDeletion. That is why you delete the namespace yourself.- The
halloApplications had the finalizer, so the ConfigMaps are already gone. Only the namespaces remain, as on Day 7.
Tried it:
argocd context --delete bobdeleted not only bob’s context, but the CLI’s entire local configuration, including the logins as admin and alice. All three contexts share the same server. So just leave thebobcontext in place. Withoutaccounts.bob, it can no longer do anything.