Sebastian Sirch // Twitter @sebastiansirch // JAX 08. September 2020
...das können schon mal >>300 Zeilen sein
Bei einer YAML-Datei bleibt es nicht...
...und aus wievielen Microservices besteht deine Anwendung?
Auf den ersten Blick einfach
Beliebige Anpassungen möglich
Wartung? Merge-Konflikte? Automatisierung?
Templates mit Parametern, basierend auf go:text/template
Helm v2: Tiller ist ein Security-Problem!
Wenn man nur das Template-Feature braucht:
$ helm template mychart -f values.yaml --output-dir ./manifests
$ kubectl apply --recursive -f ./manifests
GitOps!
Helm v3 verzichtet auf eine Server-Komponente.
values.yaml als APIhelm install - deklarativ?... provides a new, purely declarative approach to configuration customization that adheres to and leverages the familiar and carefully designed Kubernetes API.https://kubernetes.io/blog/2018/05/29/introducing-kustomize-template-free-configuration-customization-for-kubernetes/
kustomize lets you customize raw, template-free YAML files for multiple purposes, leaving the original YAML untouched and usable as is.https://github.com/kubernetes-sigs/kustomize
Kustomize should expose and teach native k8s APIs, rather than hide them.https://github.com/kubernetes-sigs/kustomize/blob/master/docs/glossary.md
Keine Templates: kustomize setzt auf eine Overlay-/Patch-Strategie
Deklarativ: jederzeit valide Kubernetes-YAML-Dateien ohne Platzhalter, volle IDE-Unterstützung inkl. Auto-Completion.
Praktische Features: Namespace, "Common-Label", ConfigMap/Secret-Änderungen
Flexibel und unabhängig: Das CLI-Tool kustomize rendert letztlich nur YAML-Output nach Stdout
$ kustomize build ~/someApp/overlays/production | kubectl apply -f -
Integration: Seit kubectl v.1.14 integriert
$ kustomize build ~/someApp/overlays/production
$ kubectl -k ~/someApp/overlays/production
~/my-app
├── base
│ ├── deployment.yaml
│ └── kustomization.yaml
└── overlays
├── prod
│ ├── deployment_env.yaml
│ ├── deployment_replicas.yaml
│ ├── deployment_volume.yaml
│ └── kustomization.yaml
└── dev
│ ├── kustomization.yaml
│ └── ...
└── ...
$ kustomize edit set image alpine=alpine:3.9
$ kustomize edit set image alpine=myimage:$COMMIT_SHA
# File: ./overlays/prod/kustomization.yaml
# ...
images:
- name: alpine
newName: alpine
newTag: "3.9"
Kustomize Binary wird benötigt!
# kustomization.template.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
namespace: __namespace__
$ sed -e "s/__namespace__/$BRANCH_SLUG/g" kustomization.template.yaml > kustomization.yaml
https://github.com/kubernetes-sigs/kustomize/blob/master/docs/eschewedFeatures.md#build-time-side-effects-from-cli-args-or-env-variables
$ helm fetch --untar --version 1.3.0 --untardir ./.chart stable/nginx-ingress
$ mkdir ./base
$ helm template --values ./values.yaml --name nginx-ingress --namespace nginx-ingress-system \
--output-dir ./base ./.chart/nginx-ingress
$ cat <<EOF > ./base/nginx-ingress/kustomization.yaml
resources:
— namespace.yaml
— clusterrole.yaml
# ...
EOF
$ kubectl apply -k ./overlays/prod/ -n nginx-ingress-system
Von Community-Projekten profitieren
Wartbare Anpassungen mit Kustomize vornehmen
https://medium.com/@sebastiansirch/why-it-is-not-about-helm-vs-kustomize-e23405de54ad
| Use Case (vereinfacht) | Tool |
|---|---|
| Deployment einer eigenen, abgeschlossenen Anwendung (z.B. Deployment, Service und Ingress) auf eigene Cluster |
Kustomize |
| ... mit vielen externen Dependencies | Kustomize (Dependencies unabhängig deployen) Helm (Wartungsaufwand in Kauf nehmen) |
|
Bereitstellung der Deployment-Deskriptoren einer abgeschlossenen
Anwendung für externe User (z.B. Open-Source-Projekt, Auslieferung an
Kunden)
Deployment-Deskriptoren
|
|
| Management betrieblicher Aspekte zur Laufzeit der Anwendung | Operator |
Day 1 (Helm, Kustomize): Deployment der Artefakte ("K8s-YAML-Handling")
Day 2 (Operator): Management von (stateful) Workloads (z.B. DBs) zur Laufzeit
apiVersion: kubedb.com/v1alpha1
kind: Snapshot
metadata:
name: instant-snapshot
namespace: demo
labels:
kubedb.com/kind: Postgres
spec:
databaseName: script-postgres
storageSecretName: gcs-secret
gcs:
bucket: kubedb-qa
Typisches Vorgehen: Operator mit Helm/Kustomize installieren