DevOps Classroom notes 01/Nov/2026

Helm Template

Chart.yaml

  • metadata for helm template
    • name
    • version
    • appversion
    • dependancy

Helm dependancy

# Name of Chart.yaml --> `C` captial
apiVersion: v2 # Helm3 suppourt communicate with kube-api sever
name: website-qt # helm chart name 
description: helm chart for qt website # description
type: application # db , Monitoring, RBAC
version: 0.1.0  # Helm chart template version - patch, minior and major
# Patch 0.1.0 - 0.1.1 , 2.1.0 - 2.1.1
# Minior 0.1.0 - 0.2.0 , 2.0.0 - 2.1.0
# Major  0.1.0 - 1.0.0, 1.0.0 - 2.0.0
appVersion: 1.16.0  # APP version or release tag version of app
dependancy:
  - name: mysql
    version: 12.0
    repostry: @mysql

templates Click here Offical docs

  • templates cantains all k8s manifests file
templates/*.yaml

templates:
    pod
    deployment
    statefulset
    demonset
    job
    RBAC -r and rb 
    service-account
    pv
    pvc..etc 

helm-playground

## Values.yaml
appName: apache2

containers:
  apache:
    image: httpd
    tag: 2.4.69
    port: 80

  initContainers:
    downloadtemplate:
      image: alpine
      tag: latest
      command:
        [
          "sh",
          "-c",
          "apk add --no-cache wget unzip && wget -O /tmp/templatemo_589_lugx_gaming.zip https://templatemo.com/tm-zip-files-2020/templatemo_589_lugx_gaming.zip && unzip /tmp/templatemo_589_lugx_gaming.zip -d /usr/local/apache2/htdocs/ && cp /usr/local/apache2/htdocs/templatemo_589_lugx_gaming/* /usr/local/apache2/htdocs/ && rm -rf /usr/local/apache2/htdocs/templatemo_589_lugx_gaming",
        ]

Deploy

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName }}-deployment
  labels:
    app: {{ .Values.appName }}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: {{ .Values.appName }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: {{ .Values.appName }}
    spec:
      initContainers:
        - name:  {{ .Values.appName }}-init-downloadtemplate
          image: "{{ .Values.containers.initContainers.downloadtemplate.image }}:{{ .Values.containers.initContainers.downloadtemplate.tag }}"
          command: {{ .Values.containers.initContainers.downloadtemplate.command }}
          volumeMounts:
            - name: {{ .Values.appName }}-html
              mountPath: /usr/local/apache2/htdocs/
      containers:
        - name: {{ .Values.appName }}
          image: "{{ .Values.containers.apache.image }}:{{ .Values.containers.apache.tag }}"
          ports:
            - containerPort: {{ .Values.containers.apache.port }}
          volumeMounts:
            - name: {{ .Values.appName }}-html
              mountPath: /usr/local/apache2/htdocs/
      volumes:
        - name: {{ .Values.appName }}-html
          emptyDir: {}


Values Types in Helm

  • string – text
  • Integer – number
  • Float – decimal (1.0 , 0.5 )
  • boolen – true or false
  • null – nothing value
  • list – many iteams like [ 80, 443] , [“dev”, “stg”]
  • map – things with multiple names Grouping
image:
  name: alpine
  tag: latest

Checking and converting type in template

  1. Typeoff – {{ typeOf .Values.replicas }} # Int or flot
  2. convert to integer {{ .Values.replicas | int }}
  3. convert to string {{ .Values.replicas | toString }}
  4. text to number {{ “8080” | atoi }}
  5. {{ .Values.appname | quote }} – “”
  6. {{ .Values.appname | upper }} – captical case Aa – AA
  7. {{ .Values.appname | lower }} – captical case Aa – aa

Helm template logic

Functions

eq – equals (when values will match )

  • EX:
{{ -eq .Values.env "prod" }}
  replicas: {{ .Values.prod.replicas }}
{{ else }}
  replicas: 1
{{ end }}

ne – not equal {{ -ne .Values.env “prod” }}

gt , Le, ge, lt

gt - greather then  > 2
ge - greather or equal  >= 2
lt - lessthen < 2
le -lessthen or equal <= 2

EX:

{{ if (gt (int .Values.replicas) 1) }}
  replicas: {{ .Values.prod.replicas }}
{{ else }}
  replicas: 1
{{ end }}

AND both true opertions need

EX:

{{ and .Values.enable -eq .Values.env “prod” }}

or either any one will be true

{{ or .Values.enable -eq .Values.env “prod” }}

not – Oppsite (condition not true)

{{ not .Values.enable }}

empty – it is null vlaue or empty

{{ empty .Values.nodeSelector }}

end end will close function or conditions

{{- end }}

if condition

EX:

nodeport:
  enable: true
{{- if  .Values.nodeport.enable }} 
apiversion: newtworking.k8s.io/v1
kind: service
....
{{- end}}

if – else if – else

{{- if  .Values.service.type "nodeport" }} 
apiversion: newtworking.k8s.io/v1
kind: service
type: nodeport
...

{{- else if  .Values.service.type "clusterip" }} 
apiversion: newtworking.k8s.io/v1
kind: service
type: nodeport
...
{{- else }} 
apiversion: newtworking.k8s.io/v1
kind: service
type: nodeport

{{- end}}
...

with – does check value is it empty and changes for vlaue .

nodeselector:
  nodeType: dev
{{- with  .Values.nodeselector }}
nodeselector:
  {{- toyaml . | nindent 2 }}
{{- end }}

Task

  1. make your deploymet to helm template and try above operations.
  2. try install Grafana helm chart

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%