Author : HASSAN MD TAREQ | Updated : 2021/05/15

What Is Helm?

Helm = Package Manager + Template Engine + Other

Links

What Is Helm Chart?

Structure of an Helm chart

helm create hello-world

hello-world /
  Chart.yaml
  values.yaml
  templates /
  charts /
  .helmignore

Chart.yaml

name: my-app
version: v0.0.1
description: A Kubernetes-Native Application

values.yaml

replicas: 3
containers:
- name: container-1
  image: my-registry.tld/my-image:tag
  env:
  - name: MY_ENV
    value: "some env var value"
  resources:
    limits:
      cpu: "200m"
      memory: "300Mi"

templates/


# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: {{ .Values.replicas | default 1 }}
  selector: ...
  template:
    metadata: ...
    spec:
      containers:
        {{- range $containerIndex, $container := Values.containers }}
        - name: {{ $container.name | default "container" | quote }}
          image: {{ $container.image | quote }}
          env:
{{ toYaml $container.env | indent 12 }}
          {{- if $container.resources }}
          resources:
            {{- with $container.resources.limits }}
            limits:
              cpu: {{ .cpu | quote }}
              memory: {{ .memory | quote }}
            {{- end }}
          {{- end }}
        {{- end }}

charts/

requirements.yaml:

dependencies:
- name: mysql
  version: 3.2.1

Install Helm

Basic Helm commands

helm create hello-world
helm lint ./hello-world

helm template ./hello-world

helm install --name hello-world ./hello-world

helm ls --all

helm upgrade hello-world ./hello-world

helm rollback hello-world 1

helm uninstall hello-world

helm package ./hello-world

helm install my-repo/hello-world --name=hello-world

Install Bridge to Kubernetes Extension

Project setup

Enable OCI support

Set HELM_EXPERIMENTAL_OCI (Open cmd/PowerShell as Administrator)

# 
# Permanently set an environment variable
# For current user only: setx VAR_NAME "VALUE"
# For all users: setx /M VAR_NAME "VALUE"
#
# Git bash: export HELM_EXPERIMENTAL_OCI=1
#
setx HELM_EXPERIMENTAL_OCI 1     # For current user only
setx /M HELM_EXPERIMENTAL_OCI 1  # For all users

Check HELM_EXPERIMENTAL_OCI is set

$env:HELM_EXPERIMENTAL_OCI     # PowerShell
echo %HELM_EXPERIMENTAL_OCI%   # cmd

Links:

Pushing Helm Chart To ACR

Set ACR_NAME environment variable:

Package chart

helm package .

Authenticate to ACR

echo xxxAcrAdminPassword | helm registry login "$($env:ACR_NAME).azurecr.io" --username $env:ACR_NAME --password-stdin
# Should return 'Login Succeeded'

Push chart to ACR

#
# "<ChartName-tag>.tgz" --> generated by helm package command
# helm push <ChartName-tag>.tgz oci://xxx.azurecr.io/helm ('/helm' is not mandatory here, you can use for example '/helm-charts')
#
helm push demoapp-0.1.0.tgz oci://"$($env:ACR_NAME).azurecr.io/helm"

Check that chart was pushed to ACR Azure portal

Azure CLI

az login
az acr repository show --name $env:ACR_NAME --repository helm/demoapp

Install ACR Helm chart to AKS

Prerequisites

# AKS credential
az login --use-device-code
az account set --subscription "xxx"
az aks get-credentials --resource-group=xxx_rg --name=xxx_aks --overwrite-existing

# Enable OCI support
$env:HELM_EXPERIMENTAL_OCI=1

# Login and update repo
echo xxxAcrAdminPassword | helm registry login "xxxacr.azurecr.io" --username xxxacr --password-stdin
helm repo update

# Pull
helm pull oci://xxxacr.azurecr.io/helm/microservicedemo --version 0.1.0

# Install
# Create K8s namespace 'demo' first
helm install microservice-demo oci://xxxacr.azurecr.io/helm/microservicedemo --version 0.1.0 --namespace demo

Uninstall

helm uninstall microservice-demo --namespace demo

Issues: