Tag 15: OCI-Registries
Ziel: Charts in eine OCI-Registry schieben, daraus installieren und per Digest pinnen – und
notesso umbauen, dass es aus einem frischen Klon baut. · Dauer: ca. 75 min · Voraussetzung: Tag 14
Briefing
- Eine OCI-Registry speichert neben Images beliebige Artefakte, auch
Charts. Kein
index.yaml, keinhelm repo add– die Adresseoci://host/pfad/chartreicht. helm registry loginwill nur den Host. Ohne TLS braucht jeder Befehl--plain-http.- Name und Version stammen aus dem Paket;
helm pushbekommt nur den Registry-Pfad ohne Chart-Namen. - Ein Tag lässt sich überschreiben, ein Digest nicht.
- Seit Tag 10 hängt
notesperfile://anplattform0.1.0, die nur noch als ignoriertes.tgzexistiert. Heute ziehtnotesseine Abhängigkeiten aus zot.
helm package ──> notes-0.12.0.tgz ──helm push──> zot :30500 charts/notes:0.12.0
│ charts/plattform:0.1.0
helm install oci://localhost:30500/charts/notes <──┘ charts/postgres:0.1.0
Drill 1: zot bekommt ein Passwort
Bisher darf jeder in zot schreiben. zot liest Benutzer aus einer
htpasswd-Datei mit bcrypt-Hashes. htpasswd (Paket
apache2-utils) fehlt auf prod, Pythons bcrypt-Modul ist
da:
# auf prod
mkdir -p ~/helm/tag15 && cd ~/helm/tag15
curl -s -o /dev/null -w "%{http_code}\n" localhost:30500/v2/_catalog
python3 -c 'import bcrypt
print("lab-zot-user:" + bcrypt.hashpw(b"lab-zot-123", bcrypt.gensalt()).decode())' \
> htpasswd
cat htpasswd
echo -n lab-zot-user:lab-zot-123 | base64Erwartet (Hash gekürzt):
200
lab-zot-user:$2b$12$HLzEVgk7Kesbk55RoTaD3O…
bGFiLXpvdC11c2VyOmxhYi16b3QtMTIz
Das Chart mountet mit mountSecret: true ein Secret nach
/secret; die Dateien darin kommen aus
secretFiles. authHeader (Base64 von
user:passwort) braucht nur der Chart-Test, die Probes
nutzen /livez und /readyz ohne Anmeldung:
# auf prod
cat > zot-values.yaml <<'EOF'
# ~/helm/tag15/zot-values.yaml – Stand Tag 15
service:
type: NodePort
nodePort: 30500
persistence: true
pvc:
storage: 2Gi
mountConfig: true
configFiles:
config.json: |-
{
"storage": { "rootDirectory": "/var/lib/registry" },
"http": {
"address": "0.0.0.0", "port": "5000",
"auth": { "htpasswd": { "path": "/secret/htpasswd" } }
},
"log": { "level": "info" }
}
mountSecret: true
authHeader: bGFiLXpvdC11c2VyOmxhYi16b3QtMTIz
resources:
requests: {cpu: 50m, memory: 64Mi}
limits: {memory: 256Mi}
EOF
diff ~/helm/tag01/zot-values.yaml zot-values.yaml | grep '^>'
helm upgrade zot zot/zot --version 0.1.135 -n zot -f zot-values.yaml \
--set-file secretFiles.htpasswd=htpasswd --wait | grep -E '^(STATUS|REVISION)'
curl -s -o /dev/null -w "%{http_code}\n" localhost:30500/v2/_catalog
curl -s -u lab-zot-user:lab-zot-123 localhost:30500/v2/_catalog; echo
curl -s -u lab-zot-user:falsch -o /dev/null -w "%{http_code}\n" \
localhost:30500/v2/_catalog
helm test zot -n zot | grep PhaseErwartet:
> # ~/helm/tag15/zot-values.yaml – Stand Tag 15
> "http": {
> "address": "0.0.0.0", "port": "5000",
> "auth": { "htpasswd": { "path": "/secret/htpasswd" } }
> },
> mountSecret: true
> authHeader: bGFiLXpvdC11c2VyOmxhYi16b3QtMTIz
STATUS: deployed
REVISION: 5
401
{"repositories":[]}
401
Phase: Succeeded
Phase: Succeeded
Achtung:
helm show values zot/zotenthält untersecretFiles.htpasswdzwei Beispielkontenadmin:adminunduser:user. Wer nurmountSecret: truesetzt undsecretFilesnicht überschreibt, betreibt eine Registry mit bekannten Passwörtern.
--set-file (Tag 3) liest die Datei als Wert – der Hash
steht damit auch im Release-Secret von zot. Für ein Labor
in Ordnung, in Produktion kommt die Datei aus einem vorhandenen
Secret.
Fortschritt speichern? Kostenlos registrieren
Drill 2: Anmelden – nur der Host
# auf prod
helm registry login localhost:30500 -u lab-zot-user -p lab-zot-123 2>&1 | tail -1
echo lab-zot-123 | helm registry login oci://localhost:30500 -u lab-zot-user \
--password-stdin --plain-http 2>&1 | tail -1
echo lab-zot-123 | helm registry login localhost:30500/charts -u lab-zot-user \
--password-stdin --plain-http 2>&1 | tail -1
echo falsch | helm registry login localhost:30500 -u lab-zot-user \
--password-stdin --plain-http 2>&1 | tail -1
echo lab-zot-123 | helm registry login localhost:30500 -u lab-zot-user \
--password-stdin --plain-http
cat ~/.config/helm/registry/config.json; echoErwartet (gekürzt):
Error: authenticating to "localhost:30500": Get "https://localhost:30500/v2/": http:
server gave HTTP response to HTTPS client
Error: invalid reference: invalid registry "oci://localhost:30500"
Error: invalid reference: invalid registry "localhost:30500/charts"
Error: authenticating to "localhost:30500": GET "http://localhost:30500/v2/":
response status code 401: Unauthorized
Login Succeeded
{
"auths": {
"localhost:30500": {
"auth": "bGFiLXpvdC11c2VyOmxhYi16b3QtMTIz"
}
}
}
Helm versucht ohne --plain-http immer HTTPS.
oci:// und Pfade lehnt login ab. Die Warnung
davor (only supports registry hostname) schneidet
tail -1 ab, ebenso die Warnung zu -p.
-p auf der Kommandozeile landet außerdem in der
Shell-History – --password-stdin ist der saubere Weg. Die
Zugangsdaten liegen Base64-kodiert (nicht verschlüsselt) in
config.json, Modus 600.
Fortschritt speichern? Kostenlos registrieren
Drill 3: Paketieren und schieben
plattform 0.1.0 gibt es nur noch als .tgz
in notes/charts/ – genau das rettest du in die Registry,
bevor es verloren geht:
# auf prod
cp ~/helm/charts/notes/charts/plattform-0.1.0.tgz .
helm package ~/helm/charts/plattform ~/helm/charts/postgres
helm push plattform-0.1.0.tgz oci://localhost:30500/charts 2>&1 | tail -1
for f in plattform-0.1.0.tgz plattform-0.2.0.tgz postgres-0.1.0.tgz; do
helm push $f oci://localhost:30500/charts --plain-http
done
curl -s -u lab-zot-user:lab-zot-123 localhost:30500/v2/_catalog; echo
curl -s -u lab-zot-user:lab-zot-123 localhost:30500/v2/charts/plattform/tags/list; echoErwartet (Digests gekürzt):
Successfully packaged chart and saved it to: /home/ubuntu/helm/tag15/plattform-0.2.0.tgz
Successfully packaged chart and saved it to: /home/ubuntu/helm/tag15/postgres-0.1.0.tgz
Error: failed to perform "Exists" on destination: Head "https://localhost:30500/v2/…
Pushed: localhost:30500/charts/plattform:0.1.0
Digest: sha256:0737a670ff13…
Pushed: localhost:30500/charts/plattform:0.2.0
Digest: sha256:0a7922062b66…
Pushed: localhost:30500/charts/postgres:0.1.0
Digest: sha256:c5891446aaf7…
{"repositories":["charts/plattform","charts/postgres"]}
{"name":"charts/plattform","tags":["0.1.0","0.2.0"]}
Auch ein Library Chart lässt sich schieben – installieren nicht, aber als Abhängigkeit ziehen. Die häufigste Falle: den Chart-Namen an die Adresse hängen.
# auf prod
helm push postgres-0.1.0.tgz oci://localhost:30500/charts/postgres --plain-http \
| head -1
D=$(curl -sI -u lab-zot-user:lab-zot-123 \
-H 'Accept: application/vnd.oci.image.manifest.v1+json' \
localhost:30500/v2/charts/postgres/postgres/manifests/0.1.0 \
| awk '/^Docker-Content-Digest/{print $2}' | tr -d '\r')
curl -s -u lab-zot-user:lab-zot-123 -X DELETE -o /dev/null -w "%{http_code}\n" \
localhost:30500/v2/charts/postgres/postgres/manifests/$DErwartet:
Pushed: localhost:30500/charts/postgres/postgres:0.1.0
202
Helm hängt den Namen selbst an – aus …/charts/postgres
wird charts/postgres/postgres. Gelöscht wird über die
Registry-API per Digest; Helm hat dafür keinen Befehl.
Fortschritt speichern? Kostenlos registrieren
Drill 4: Aus der Registry nutzen
# auf prod
helm package ~/helm/charts/helper | cut -c1-40
helm push helper-0.2.0.tgz oci://localhost:30500/charts --plain-http
helm show chart oci://localhost:30500/charts/helper --version 0.2.0 --plain-http \
2>/dev/null | grep -E '^(name|version)'
helm show chart oci://localhost:30500/charts/helper 2>&1 | tail -1
helm pull oci://localhost:30500/charts/helper --version 0.2.0 --plain-http \
--untar -d pull 2>/dev/null
tree pull -L 3 | head -6
helm install h oci://localhost:30500/charts/helper --version 0.2.0 --plain-http \
-n tag15 --create-namespace --wait 2>/dev/null | grep -E '^(STATUS|REVISION)'
helm get metadata h -n tag15 | grep -E '^(CHART|VERSION)'Erwartet (gekürzt):
Successfully packaged chart and saved it
Pushed: localhost:30500/charts/helper:0.2.0
Digest: sha256:d744b062d298…
name: helper
version: 0.2.0
Error: Get "https://localhost:30500/v2/charts/helper/tags/list": http: server gave
HTTP response to HTTPS client
pull
└── helper
├── Chart.lock
├── Chart.yaml
├── charts
│ └── plattform
STATUS: deployed
REVISION: 1
CHART: helper
VERSION: 0.2.0
Ohne --version fragt Helm die Tag-Liste ab und nimmt die
höchste SemVer-Version (Bereiche wie ~0.2.0 gehen auch).
Das Paket enthält plattform bereits – wer es installiert,
braucht keine Abhängigkeiten mehr aufzulösen. Woher das Chart kam,
speichert Helm nicht: get metadata kennt nur Name und
Version.
Ohne Anmeldung kommt nichts aus zot; Zugangsdaten gehen auch pro Befehl:
# auf prod
helm registry logout localhost:30500
helm show chart oci://localhost:30500/charts/helper --version 0.2.0 --plain-http \
2>&1 | grep -o 'basic credential not found'
helm show chart oci://localhost:30500/charts/helper --version 0.2.0 --plain-http \
--username lab-zot-user --password lab-zot-123 2>/dev/null | grep '^version'
echo lab-zot-123 | helm registry login localhost:30500 -u lab-zot-user \
--password-stdin --plain-httpErwartet:
Removing login credentials for localhost:30500
basic credential not found
version: 0.2.0
Login Succeeded
Fortschritt speichern? Kostenlos registrieren
Drill 5: Per Digest pinnen
Die Meldungen Pulled: und Digest: schreibt
Helm nach stderr:
# auf prod
R=oci://localhost:30500/charts/helper
D=$(helm show chart $R --version 0.2.0 --plain-http 2>&1 | awk '/^Digest/{print $2}')
echo $D
helm upgrade h $R@$D --plain-http -n tag15 2>&1 | grep -E '^(Pulled|Release)'
helm upgrade h $R@${D%?}0 --plain-http -n tag15 2>&1 | tail -1
helm upgrade h $R:0.1.0@$D --plain-http -n tag15 2>&1 | grep -E '^(Pulled|Release)'
helm upgrade h $R@$D --version 9.9.9 --plain-http -n tag15 2>&1 \
| grep -E '^(Pulled|Release)'Erwartet (Digests gekürzt):
sha256:d744b062d298904de3c1f44c81d7b0145eef9a86a08615534959d1d7e9c5955b
Pulled: localhost:30500/charts/helper@sha256:d744b062d298…
Release "h" has been upgraded. Happy Helming!
Error: failed to perform "FetchReference" on source:
localhost:30500/charts/helper@sha256:d744b062d298…e9c59550: not found
Pulled: localhost:30500/charts/helper@sha256:d744b062d298…
Release "h" has been upgraded. Happy Helming!
Pulled: localhost:30500/charts/helper@sha256:d744b062d298…
Release "h" has been upgraded. Happy Helming!
Ein falscher Digest scheitert, bevor etwas installiert wird. Steht
ein Digest in der Adresse, gewinnt er: Den Tag 0.1.0 gibt
es für helper gar nicht, und --version 9.9.9
ignoriert Helm kommentarlos. Wer per Digest pinnt, sollte keinen Tag
daneben schreiben – der täuscht eine Prüfung nur vor.
Fortschritt speichern? Kostenlos registrieren
Drill 6: Tags sind nicht fest
Ein Wegwerf-Chart mit Build-Metadaten:
# auf prod
mkdir -p mini/templates
printf 'apiVersion: v2\nname: mini\nversion: 1.0.0+build.1\n' > mini/Chart.yaml
cat > mini/templates/cm.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-mini
data:
stand: "eins"
EOF
helm package mini >/dev/null
helm push mini-1.0.0+build.1.tgz oci://localhost:30500/charts --plain-http 2>&1 \
| head -2
helm show chart oci://localhost:30500/charts/mini --version 1.0.0+build.1 \
--plain-http 2>/dev/null | grep '^version'
helm show chart oci://localhost:30500/charts/mini --version 1.0.0_build.1 \
--plain-http 2>&1 | grep ErrorErwartet (gekürzt):
Pushed: localhost:30500/charts/mini:1.0.0_build.1
Digest: sha256:1536cee423da…
version: 1.0.0+build.1
Error: improper constraint: "1.0.0_build.1"
OCI-Tags erlauben kein +. Helm schreibt beim Push
_ und übersetzt beim Pull zurück – angeben musst du immer
die SemVer-Form mit +. Jetzt dieselbe Version dreimal
schieben, beim dritten Mal mit anderem Inhalt:
# auf prod
sed -i 's/^version: .*/version: 1.0.0/' mini/Chart.yaml
for stand in eins eins zwei; do
sed -i "s/stand: .*/stand: \"$stand\"/" mini/templates/cm.yaml
helm package mini >/dev/null; sleep 1
helm push mini-1.0.0.tgz oci://localhost:30500/charts --plain-http 2>&1 \
| awk '/^Digest/{print $2}' | tee -a digests.txt
done
helm template x oci://localhost:30500/charts/mini --version 1.0.0 --plain-http \
2>/dev/null | grep standErwartet (Digests gekürzt):
sha256:554fe4004198…
sha256:cdf6e396b7db…
sha256:21799de5c5c8…
stand: "zwei"
zot überschreibt den Tag ohne Rückfrage. Schon das zweite Paket mit
gleichem Inhalt hat einen anderen Digest – das .tgz enthält
die Änderungszeit jeder Datei, und sed -i schreibt die
Datei neu (unveränderte Dateien ergeben denselben Digest, Tag 16). Wer
den alten Digest gepinnt hat, bekommt weiter das alte Paket:
# auf prod
helm template x oci://localhost:30500/charts/mini@$(head -1 digests.txt) --plain-http \
2>/dev/null | grep standErwartet:
stand: "eins"
Genau dafür gibt es den Digest-Pin. Unveränderliche Tags musst du in der Registry erzwingen oder in der Pipeline (nie eine vorhandene Version erneut schieben, Tag 18).
Fortschritt speichern? Kostenlos registrieren
Drill 7: notes zieht aus der Registry
Zuerst der Beweis, dass das Repo heute kaputt ist – ein frischer Klon:
# auf prod
git clone -q ~/helm/charts klon
helm dependency build klon/notes 2>&1 | tail -1
helm dependency list klon/notes
rm -rf klonErwartet:
Error: can't get a valid version for dependency plattform
NAME VERSION REPOSITORY STATUS
postgres ~0.1.0 file://../postgres missing
plattform ~0.1.0 file://../plattform missing
Im Ordner plattform steht 0.2.0, notes will
~0.1.0. Jetzt die Abhängigkeiten auf zot umstellen und die
Chart-Version erhöhen:
# auf prod
cd ~/helm/charts
cat > notes/Chart.yaml <<'EOF'
# notes/Chart.yaml – Stand Tag 15
apiVersion: v2
name: notes
description: Notiz-API mit PostgreSQL – Übungschart aus „Helm Charts zum Anfassen“
type: application
version: 0.12.0
appVersion: "0.7.1"
kubeVersion: ">=1.33.0-0"
maintainers:
- name: Helm Lab
email: [email protected]
dependencies:
- name: postgres
version: "~0.1.0"
repository: oci://localhost:30500/charts
condition: postgres.enabled
- name: plattform
version: "~0.1.0"
repository: oci://localhost:30500/charts
EOF
helm dependency update notes 2>&1 | tail -1
helm dependency update notes --plain-http --skip-refresh 2>&1 \
| grep -E '^(Pulled|Saving)'
grep -A2 'name: plattform' notes/Chart.lockErwartet (gekürzt):
Error: could not retrieve list of tags for repository oci://localhost:30500/charts:
Get "https://localhost:30500/v2/charts/postgres/tags/list": http: server gave HTTP …
Saving 2 charts
Pulled: localhost:30500/charts/postgres:0.1.0
Pulled: localhost:30500/charts/plattform:0.1.0
- name: plattform
repository: oci://localhost:30500/charts
version: 0.1.0
Bei oci:// gibt repository nur den Pfad
ohne Chart-Namen an; den Bereich ~0.1.0
löst Helm über die Tag-Liste auf. --skip-refresh spart das
Aktualisieren der HTTP-Repos (hier zot aus Tag 1).
helper bekommt dieselbe Umstellung in einer Zeile:
# auf prod
sed -i 's|file://../plattform|oci://localhost:30500/charts|;
s|^version: 0.2.0|version: 0.2.1|; s|Stand Tag 10|Stand Tag 15|' helper/Chart.yaml
helm dependency update helper --plain-http --skip-refresh 2>&1 | grep Pulled
helm upgrade notes ./notes -n notes -f values/prod.yaml --wait | grep REVISION
helm upgrade helper ./helper -n notes --wait | grep REVISION
git add -A
git commit -qm "Tag 15: Abhängigkeiten aus zot, notes 0.12.0, helper 0.2.1"
git log --oneline -1Erwartet:
Pulled: localhost:30500/charts/plattform:0.2.0
REVISION: 30
REVISION: 3
8daf326 Tag 15: Abhängigkeiten aus zot, notes 0.12.0, helper 0.2.1
Und wieder ein frischer Klon – diesmal baut er. Das Ergebnis geht als
notes 0.12.0 in die Registry, und der Prod-Release kommt ab
jetzt von dort:
# auf prod
cd ~/helm/tag15 && git clone -q ~/helm/charts klon
helm dependency build klon/notes --plain-http 2>&1 | grep Pulled
helm package klon/notes >/dev/null
helm push notes-0.12.0.tgz oci://localhost:30500/charts --plain-http 2>&1 | head -1
helm package ~/helm/charts/helper >/dev/null
helm push helper-0.2.1.tgz oci://localhost:30500/charts --plain-http 2>&1 | head -1
cd ~/helm/charts
helm upgrade notes oci://localhost:30500/charts/notes --version 0.12.0 --plain-http \
-n notes -f values/prod.yaml --wait 2>/dev/null | grep REVISION
diff <(helm get manifest notes -n notes --revision 30) \
<(helm get manifest notes -n notes --revision 31)Erwartet:
Pulled: localhost:30500/charts/postgres:0.1.0
Pulled: localhost:30500/charts/plattform:0.1.0
Pushed: localhost:30500/charts/notes:0.12.0
Pushed: localhost:30500/charts/helper:0.2.1
REVISION: 31
34c34
< revision: "30"
---
> revision: "31"
Revision 30 kam aus dem Arbeitsordner, Revision 31 aus dem Klon über
die Registry – bis auf die Revisionsnummer in der ConfigMap identisch.
Chart.lock sorgt dafür, dass dependency build
genau 0.1.0 holt, auch wenn später 0.1.1 erscheint.
Fortschritt speichern? Kostenlos registrieren
Drill 8: Hineinschauen und abgrenzen
# auf prod
helm repo add lab oci://localhost:30500/charts 2>&1 | cut -c1-80
helm search repo notes
A="-s -u lab-zot-user:lab-zot-123"
curl $A -H 'Accept: application/vnd.oci.image.manifest.v1+json' \
localhost:30500/v2/charts/notes/manifests/0.12.0 | jq '{config, layers}'Erwartet (Digests gekürzt):
Error: looks like "oci://localhost:30500/charts" is not a valid chart repository
No results found
{
"config": {
"mediaType": "application/vnd.cncf.helm.config.v1+json",
"digest": "sha256:7e57ff297ebf…",
"size": 502
},
"layers": [
{
"mediaType": "application/vnd.cncf.helm.chart.content.v1.tar+gzip",
"digest": "sha256:62c8772113b8…",
"size": 6497
}
]
}
Ein Chart ist ein OCI-Artefakt mit zwei Teilen: Die Config ist
Chart.yaml als JSON, die einzige Schicht ist das
.tgz. Beides lässt sich direkt über die Registry-API
holen:
# auf prod
M=$(curl $A -H 'Accept: application/vnd.oci.image.manifest.v1+json' \
localhost:30500/v2/charts/notes/manifests/0.12.0)
curl $A localhost:30500/v2/charts/notes/blobs/$(echo $M | jq -r .config.digest) \
| jq -c '{name, version, deps: [.dependencies[].repository]}'
echo $M | jq -r '.layers[0].digest' | cut -c8-19
sha256sum ~/helm/tag15/notes-0.12.0.tgz | cut -c1-12
D=$(curl $A -I -H 'Accept: application/vnd.oci.image.manifest.v1+json' \
localhost:30500/v2/charts/notes/manifests/0.12.0 \
| awk '/^Docker-Content-Digest/{print $2}' | tr -d '\r')
curl $A localhost:30500/v2/charts/notes/referrers/$D | jq -c .Erwartet:
{"name":"notes","version":"0.12.0","deps":["oci://localhost:30500/charts","oci://loca…
62c8772113b8
62c8772113b8
{"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","manifests":[]}
Der Schicht-Digest ist die SHA-256 deines .tgz. Die
Referrers-Liste ist noch leer – in Tag 16 hängt dort die
cosign-Signatur. Das Werkzeug oras (oras manifest fetch,
oras discover) zeigt dasselbe bequemer; im Labor ist es
nicht installiert, curl reicht.
| OCI-Registry | HTTP-Repository | |
|---|---|---|
| Einrichtung | vorhandene Registry | Webserver + index.yaml |
helm repo add, search repo |
nein | ja |
| Adresse | oci://host/pfad/chart |
repo/chart |
| Pin per Digest | ja | nein |
Fortschritt speichern? Kostenlos registrieren
Übung: Speed-Drills
- Welche Versionen von
plattformliegen in zot? Zeitziel: 20 s - Ermittle den Digest von
notes0.12.0, ohne das Chart zu laden. Zeitziel: 45 s - Welches Image rendert
notes0.12.0 aus zot mitvalues/prod.yaml? Nur das Deployment. Zeitziel: 45 s - Welche Version von
helperinstalliert Helm ohne--version? Zeitziel: 20 s
Lösung
# auf prod
curl -s -u lab-zot-user:lab-zot-123 localhost:30500/v2/charts/plattform/tags/list \
| jq -c .tags
curl -sI -u lab-zot-user:lab-zot-123 \
-H 'Accept: application/vnd.oci.image.manifest.v1+json' \
localhost:30500/v2/charts/notes/manifests/0.12.0 | grep -i docker-content-digest
cd ~/helm/charts
helm template t oci://localhost:30500/charts/notes --version 0.12.0 --plain-http \
-f values/prod.yaml -s templates/deployment.yaml 2>/dev/null | grep 'image:'
helm show chart oci://localhost:30500/charts/helper --plain-http 2>/dev/null \
| grep '^version'Erwartet (Digest gekürzt):
["0.1.0","0.2.0"]
Docker-Content-Digest: sha256:17f55276c74f…
image: "ghcr.io/thomaszachmann/notes-api:0.7.1"
version: 0.2.1
Ohne -f values/prod.yaml bricht Aufgabe 3 mit
apiKey.existingSecret fehlt ab – das required
aus Tag 8 gilt auch für Charts aus der Registry.
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
# auf prod
helm list -n notes --filter '^notes$'Erwartet: Revision 31, notes-0.12.0,
deployed.
# auf prod
curl -s -o /dev/null -w "%{http_code}\n" localhost:30500/v2/_catalogErwartet: 401
# auf prod
grep repository ~/helm/charts/notes/Chart.yamlErwartet: zweimal
repository: oci://localhost:30500/charts, kein
file://.
# auf prod
helm test notes -n notes | grep PhaseErwartet: Phase: Succeeded
Challenge
Stelle zot auf TLS mit einer eigenen CA um (Zertifikat für
localhost, 127.0.0.1 und
172.16.0.123) und hole notes 0.12.0 ohne
--plain-http. Zeige, dass ohne CA nichts geht. Danach
zurück auf HTTP.
Hinweis: zot will in http.tls die Pfade
zu cert und key; beide passen als weitere
Schlüssel in secretFiles, und die Probes brauchen
httpGet.scheme: HTTPS.
Lösung
CA und Server-Zertifikat mit openssl:
# auf prod
cd ~/helm/tag15 && mkdir -p tls && cd tls
openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.crt -days 30 \
-subj "/CN=Helm Lab CA" 2>/dev/null
openssl req -newkey rsa:2048 -nodes -keyout zot.key -out zot.csr -subj "/CN=zot" \
2>/dev/null
printf "subjectAltName=DNS:localhost,IP:127.0.0.1,IP:172.16.0.123\n" > san.ext
openssl x509 -req -in zot.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 30 \
-extfile san.ext -out zot.crt
openssl x509 -in zot.crt -noout -issuer -ext subjectAltName
cd ..Erwartet:
Certificate request self-signature ok
subject=CN = zot
issuer=CN = Helm Lab CA
X509v3 Subject Alternative Name:
DNS:localhost, IP Address:127.0.0.1, IP Address:172.16.0.123
Eine zweite Werte-Datei überlagert nur, was sich ändert (Vorrang aus Tag 3):
# auf prod
cat > zot-tls.yaml <<'EOF'
# ~/helm/tag15/zot-tls.yaml – Stand Tag 15 (Challenge)
configFiles:
config.json: |-
{
"storage": { "rootDirectory": "/var/lib/registry" },
"http": {
"address": "0.0.0.0", "port": "5000",
"tls": { "cert": "/secret/tls.crt", "key": "/secret/tls.key" },
"auth": { "htpasswd": { "path": "/secret/htpasswd" } }
},
"log": { "level": "info" }
}
httpGet:
scheme: HTTPS
EOF
helm upgrade zot zot/zot --version 0.1.135 -n zot -f zot-values.yaml -f zot-tls.yaml \
--set-file secretFiles.htpasswd=htpasswd \
--set-file 'secretFiles.tls\.crt=tls/zot.crt' \
--set-file 'secretFiles.tls\.key=tls/zot.key' --wait | grep REVISION
kubectl -n zot get secret zot-secret -o jsonpath='{.data}' | jq -r 'keys[]'
curl -s -u lab-zot-user:lab-zot-123 https://localhost:30500/v2/_catalog
echo "curl exit $?"
curl -s -u lab-zot-user:lab-zot-123 --cacert tls/ca.crt \
https://localhost:30500/v2/_catalog; echo
helm test zot -n zot | grep -c SucceededErwartet:
REVISION: 6
htpasswd
tls.crt
tls.key
curl exit 60
{"repositories":["charts/helper","charts/mini","charts/notes","charts/plattform",…
2
Der Punkt im Schlüssel tls.crt muss in
--set-file mit \. maskiert werden, sonst wird
daraus tls: {crt: …}. Jetzt Helm:
# auf prod
helm show chart oci://localhost:30500/charts/notes --version 0.12.0 2>&1 | tail -1
helm show chart oci://localhost:30500/charts/notes --version 0.12.0 --plain-http \
2>&1 | tail -1
echo lab-zot-123 | helm registry login localhost:30500 -u lab-zot-user \
--password-stdin --ca-file tls/ca.crt
helm show chart oci://localhost:30500/charts/notes --version 0.12.0 \
--ca-file tls/ca.crt 2>/dev/null | grep '^version'
git clone -q ~/helm/charts klon2
helm dependency build klon2/notes --ca-file tls/ca.crt 2>&1 | grep PulledErwartet (gekürzt):
Error: failed to perform "FetchReference" on source: Get "https://localhost:30500/v2/
charts/notes/manifests/0.12.0": tls: failed to verify certificate: x509: certificate
signed by unknown authority
Error: failed to perform "FetchReference" on source: GET "http://localhost:30500/v2/
charts/notes/manifests/0.12.0": response status code 400: Bad Request
Login Succeeded
version: 0.12.0
Pulled: localhost:30500/charts/postgres:0.1.0
Pulled: localhost:30500/charts/plattform:0.1.0
Chart.yaml muss nicht geändert werden:
oci:// sagt nichts über HTTP oder HTTPS, das entscheiden
--plain-http bzw. --ca-file beim Aufruf. Auch
die gespeicherte Anmeldung gilt weiter, sie hängt nur am Host.
--insecure-skip-tls-verify ginge auch – und prüft dann gar
nichts mehr. Zurück auf HTTP, wie es die nächsten Tage erwarten:
# auf prod
helm rollback zot 5 -n zot --wait --description "zurück auf HTTP mit htpasswd"
curl -s -o /dev/null -w "%{http_code}\n" -u lab-zot-user:lab-zot-123 \
localhost:30500/v2/_catalog
rm -rf klon2Erwartet:
Rollback was a success! Happy Helming!
200
Fortschritt speichern? Kostenlos registrieren
Aufräumen
# auf prod
cd ~/helm/tag15
helm uninstall h -n tag15
kubectl delete namespace tag15
for t in 1.0.0 1.0.0_build.1; do
curl -s -u lab-zot-user:lab-zot-123 -X DELETE -o /dev/null -w "%{http_code}\n" \
localhost:30500/v2/charts/mini/manifests/$t
done
curl -s -u lab-zot-user:lab-zot-123 localhost:30500/v2/charts/mini/tags/list; echo
rm -rf klon pull mini digests.txtErwartet:
release "h" uninstalled
namespace "tag15" deleted
202
202
{"name":"charts/mini","tags":[]}
zot löscht hier ausnahmsweise auch per Tag. Dabei verschwindet nur
der Tag, das Manifest bleibt unmarkiert liegen – der leere Eintrag
charts/mini steht weiter im Katalog. Erst die Garbage
Collection von zot (Standard: alle 60 Minuten, für Manifeste älter als
60 Minuten) räumt es ab und meldet im Log
removing idle repo; im Labor war mini so nach
knapp zwei Stunden weg. Wer per Digest löscht, entfernt das Manifest
sofort, und mit dem letzten verschwindet auch das Repo aus dem Katalog
(Tag 20, Anhang B). plattform, postgres,
helper und notes bleiben für die nächsten Tage
in zot.
Interview-Notiz
- Warum Charts in einer OCI-Registry? Eine Infrastruktur für
Images und Charts, mit denselben Rechten, Scans, Replikation und
Signaturen; kein
index.yaml, Pin per Digest möglich. - Was ist der Unterschied zwischen Tag und Digest? Ein Tag ist ein beweglicher Name, den jeder mit Schreibrecht überschreiben kann. Der Digest ist die Prüfsumme des Manifests – stimmt er nicht, installiert Helm nicht.
- Warum taugt
file://nicht für geteilte Bibliotheken? Es kennt nur die Version, die gerade im Ordner liegt. Wer eine ältere braucht, hängt an einem.tgz, das kein Git versioniert.
Enterprise-Notiz
- Registry mit TLS aus der Firmen-CA (CA im Systemspeicher der Runner,
dann entfällt
--ca-file), Anmeldung über Robot-Konten oder OIDC-Token statt htpasswd. - Unveränderliche Tags in der Registry einschalten (Harbor, ECR, Artifact Registry können das) oder in der Pipeline erzwingen; in GitOps-Werkzeugen per Digest pinnen.
- Getrennte Pfade bzw. Projekte für Bibliotheken
(
charts/lib) und Anwendungen, mit Leserecht für alle und Schreibrecht nur für die Pipeline. - Zugangsdaten liegen in
~/.config/helm/registry/config.jsonnur Base64-kodiert – auf geteilten Runnern--registry-configauf ein temporäres Verzeichnis setzen und danach löschen. - Öffentliche Charts (z. B. zot, Traefik) in die eigene Registry spiegeln, damit ein Ausfall oder Löschen beim Anbieter keine Deployments stoppt.