https___bestdotnettraining.azureedge.net_documents_Kubernetes_12_Helm_12_Helm
https___bestdotnettraining.azureedge.net_documents_Kubernetes_12_Helm_12_Helm
Note: Helm Compares Old Chart, New Chart and Live State and creates a new Patch that updates the cluster.
2. Helm is a Templating Engine.
a. We can define a common blueprint (template) for multiple YAML files.
b. In a template file, dynamics values replaced their placeholders. The values come from a file called
values.yaml.
Helm versions.
Installing on Windows
Installing on Linux
curl https://get.helm.sh/helm-v3.8.2-darwin-amd64.tar.gz
tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/helm
helm version --short
Overview Chart.yaml
Note: Helm does not wait until all of the resources are running before it exits. Many charts require Docker
images that are over 600M in size, and may take a long time to install into the cluster.
Notes:
Chart is the definition of our Application
Release is the instance of the chart running in the Kubernetes cluster.
Release revision: Change the existing YAML files and update the chart.
Chart Version refers to the change in chart file structure. You may add new YAML files to chart.
Helm Commands
helm create [chart]
helm install [release] [chart] Install a Release
helm upgrade [release] [chart] Upgrade a Release version
helm rollback [release] [version] Rollback to a Release version
helm history [release] Print Release history
helm status [release] Display Release status
helm get all [release] Show details of a release
helm uninstall [release] Uninstall a Release
helm list List Release
Rollback:
1. helm history demo-mywebapp
2. helm rollback demo-mywebapp 1
3. helm history demo-mywebapp
Uninstall:
helm uninstall demo-mywebapp
Helm Templates
Helm Template Engine:
It works on client side.
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-{{.Release.Name}}-{{.Chart.Name}}
spec:
replicas: {{.Values.replicaCount}}
selector:
matchLabels:
app: nginx-{{.Release.Name}}-{{.Chart.Name}}-app
template:
metadata:
name: nginx-{{.Release.Name}}-{{.Chart.Name}}-pod
labels:
app: nginx-{{.Release.Name}}-{{.Chart.Name}}-app
spec:
containers:
- name: nginx-{{.Release.Name}}-{{.Chart.Name}}-con
image: {{.Values.image.repository}}:{{.Values.image.tag}}
ports:
- containerPort: 80
Service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service-{{ .Release.Name }}-{{ .Chart.Name }}
spec:
type: {{.Values.service.type}}
selector:
app: nginx-{{ .Release.Name }}-{{ .Chart.Name }}-app
ports:
- protocol: TCP
port: {{ .Values.service.port }}
targetPort: 80
Values.yaml
replicaCount: 2
image:
repository: nginx
tag: "1.17.0"
service:
type: LoadBalancer
port: 8090
Test the template using
helm template mywebapp
helm install demo1 mywebapp --dry-run
Run the chart
helm install demo1 mywebapp
Upgrade the chart
change the image tag in values.yaml
helm upgrade demo-mywebapp mywebapp
You can also override the values in Values.yaml using the below command
Values.yaml
service:
type: NodePort
name: myservice-with-a-very-long name-that-will-be truncated-by-trunc and-trimsuffix-and which-is-too-long for-
Kubernetes
labels
port: 80
mongodbRootPassword: T9rYGFAMGE
Examples:
{{ Values.service.name | default .Chart.Name }} #Chart Name will be used as default value for
Values.servce.name doesn’t exist
{{ .Values.service.name | trunc 63 | trimSuffix "-" }}
{{ .Values.mongodbRootPassword | b64enc | quote }}
Formatted Output:
apiVersion: v1
kind: Service
metadata:
name: nginx-service-{{ printf "%s-%s" .Release.Name .Chart.Name }}
spec:
selector:
app: nginx-{{.Release.Name}}-{{.Chart.Name}}-app
{{ with .Values.service}}
type: {{ .type }}
ports:
- protocol: TCP
port: {{ .port | default "8080"}}
targetPort: 80
{{ end }}
Logical Operators
Examples:
{{- if and .adminEmail (or .serviceAccountJson .existingSecret) }}
{{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nfsNodePort))) }}
{{- if or .Values.rbac.pspEnabled (and .Values.rbac.namespaced (or .Values.sidecar.dashboards.enabled
.Values.sidecar.datasources.enabled)) }}
Conditions:
Loops:
Variables
apiVersion: v1
kind: Service
metadata:
name: nginx-service-{{ printf "%s-%s" .Release.Name .Chart.Name }}
spec:
{{- $serviceSelector := printf "%s-%s" .Release.Name .Chart.Name }}
{{- with .Values.service}}
type: {{ .type }}
selector:
app: nginx-{{ $serviceSelector }}-app
ports:
- protocol: TCP
port: {{ .port | default "8080"}}
targetPort: 80
{{ end }}
OR
use $ for accessing Global Built-in Variables
apiVersion: v1
kind: Service
metadata:
name: nginx-service-{{ printf "%s-%s" .Release.Name .Chart.Name }}
spec:
{{ with .Values.service}}
type: {{ .type }}
selector:
app: nginx-{{$.Release.Name}}-{{$.Chart.Name}}-app
ports:
- protocol: TCP
port: {{ .port | default "8080"}}
targetPort: 80
{{ end }}
Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-{{ include "mychart.fullname" . }}-dep
spec:
replicas: {{.Values.replicaCount}}
...
Registry
Repository
Packages/charts
Helm Dependency
list: list the dependencies for the given chart
update: update charts/ based on the contents of Chart.yaml
build: rebuild the charts/ directory based on the Chart.lock file
1. Update Chart.yaml
apiVersion: v2
name: mywebapp
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "1.16.0"
dependencies:
- name: mysql
version: ~8.9.0
repository: https://charts.bitnami.com/bitnami
2. helm dependency list mywebapp
3. helm dependency update mywebapp
Note: Chart.lock file is added to chart with hardcoded versions.