operations
show all releases in all namespaces without any filter applied..
helm list -Aa
get the values for a helm release..
helm get values ${NAME}
helm get values ${NAME} --all
render templates..
helm template ${NAME} . -f values.yaml -s templates/deployment.yaml
get the helm release secret in plain text..
kubectl get secrets sh.helm.release.v1.traefik.v1 -n traefik -o jsonpath='{.data.release}' | base64 --decode | base64 --decode | gzip -d | jq
service accounts
https://github.com/kubernetes/kubernetes/issues/76367#issuecomment-481689160
mount directories
Mounting multiple directories to a pod while preserving the original directory structure.
Let’s say we have a directory with three files and a subdirectory with three more files inside it and we want to mount all of these into a pod..
.
├── animals
│ ├── cat
│ ├── dog
│ └── mouse
├── blue
├── green
└── magenta
We do the following..
- inside the Helm chart we create a directory called
dataand copy all the files - under the
templatesdirectory we create aconfigmap.yamlfile..apiVersion: v1 kind: ConfigMap metadata: name: data data: {{ $files := .Files }} {{ $filesLocalPath := "data/**" }} {{ $trimPrefixUnderscores := "data_" }} {{ range $path, $content := .Files.Glob $filesLocalPath }} {{ regexReplaceAll "\\/+" $path "_" | trimPrefix $trimPrefixUnderscores | indent 2 }}: |- {{ $files.Get $path | indent 4 }} {{ end }} - again under the
templatesdirectory we create adeployment.yamlfile..apiVersion: apps/v1 kind: Deployment metadata: name: demo spec: replicas: 1 selector: matchLabels: app: demo template: metadata: labels: app: demo annotations: checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} # we add this spec: containers: - name: app image: nginx volumeMounts: # we add these {{ $filesLocalPath := "data/**" }} # {{ $trimPrefixSlashes := "data/" }} # {{ $trimPrefixUnderscores := "data_" }} # {{ range $path, $content := .Files.Glob $filesLocalPath }} # - name: data # mountPath: /etc/data/{{ $path | trimPrefix $trimPrefixSlashes }} # subPath: {{ regexReplaceAll "\\/+" $path "_" | trimPrefix $trimPrefixUnderscores }} # readOnly: true # {{ end }} # volumes: # - name: data # configMap: # name: data #
How it works..
- we use a ConfigMap to store the path and the content of the files in a key-value format
- since the ConfigMap can not store file paths because a ConfigMap key can only contain alphanumeric characters and the
.,-and_symbols, we replace the/from the paths with_so the fileanimals/catis stored asanimals_cat - when we mount the file to the pod we do the opposite and replace the
_with/
Considerations..
- a disadvantage of this approach is that we can’t have files with names that contain underscores
- the files from the ConfigMap are mounted when the pod starts and to update them the pod must be restarted or redeployed, to automate this we add an annotation to the pod with the SHA256 checksum of the rendered ConfigMap so when it changes the pod is automatically recreated
- the files from the ConfigMap are mounted on the pod individually and not as a single directory, meaning that the contents of the
animalsdirectory are mounted asdata/animals/cat,data/animals/doganddata/animals/mouserather than replacing the entiredata/animalsdirectory of the pod, so if thedata/animalsdirectory already exists in the pod and contains files not defined in the ConfigMap (for exampledata/animals/tiger) those files will remain present after the ConfigMap is mounted
extra objects
When we need to apply additional YAML manifests alongside a Helm chart..
- under
templateswe create a file calledextra-manifests.yamlwith the following content..{{ range .Values.extraObjects }} --- {{ if typeIs "string" . }} {{- tpl . $ }} {{- else }} {{- tpl (toYaml .) $ }} {{- end }} {{ end }} - in the values.yaml file we add the following block
extraObjects: []
Example usage..
extraObjects:
- apiVersion: v1
kind: ConfigMap
metadata:
labels:
name: blue
data:
color: "blue"
- apiVersion: v1
kind: ConfigMap
metadata:
labels:
name: green
data:
color: "green"