Overview:

In the previous post, we explored Option 1: Configure and deploy app to AKS without Helm Chart, in this blog we will explore What is Helm and configure and deploy app using Helm Chart.

What is Helm?

Helm is an open-source packaging tool that helps you install and manage the lifecycle of Kubernetes applications. Similar to Linux package managers like APT and Yum, Helm manages Kubernetes charts, which are packages of pre-configured Kubernetes resources.

In this post, you use Helm to package and run an application on AKS.

What is Dapr?

Deploy an application using the Dapr cluster extension for Azure Kubernetes Service (AKS) or Arc-enabled Kubernetes.

You use the Dapr cluster extension in an AKS or Arc-enabled Kubernetes cluster. You deploy a hello world example, which consists of a Python application that generates messages and a node application that consumes and persists the messages.

What is Draft?

Draft is an open-source project that streamlines Kubernetes development.

It takes a non-containerized application and generates the DockerFiles, Kubernetes manifests, Helm charts, Kustomize configurations, and other artifacts associated the application. The Azure Kubernetes Service (AKS) DevX extension for Visual Studio Code enhances non-cluster experiences, allowing you to create deployment files to deploy your applications to AKS.

Draft is the available feature included in the DevX extension.

Why Helm?

Let’s focus on Helm and understand why we need Helm.

Helm is a tool that helps you manage Kubernetes applications. Helm uses a packaging format called charts, which are collections of YAML templates that describe a related set of Kubernetes resources. Helm can create new charts from scratch, or package existing Kubernetes resources into charts.

Helm can be useful for AKS (Azure Kubernetes Service), which is a managed Kubernetes service that lets you quickly deploy and manage clusters. Helm can help you with the following use cases for AKS:

  • Installing and upgrading applications: Helm can install and upgrade complex applications on AKS with a single command. Helm can also roll back to a previous version of a chart if something goes wrong.
  • Sharing and reusing applications: Helm can package and distribute applications as charts, which can be hosted in public or private repositories. Helm can also fetch and install charts from any repository. This makes it easy to share and reuse applications across different AKS clusters or environments.
  • Managing application dependencies: Helm can automatically download and install charts that are required by another chart. Helm can also update the dependencies to match the versions specified in the parent chart. This simplifies the management of complex applications that have multiple dependencies.

Examples of activities that you can carry out for AKS with and without Helm charts:

Let’s explore few examples of activities that you can carry out for AKS with and without Helm charts. Here are some scenarios:

  • Deploying a WordPress application:

Without Helm, you would need to create several YAML files to define the Kubernetes resources for the WordPress application, such as deployments, services, persistent volumes, and secrets.

You would also need to manually apply each YAML file using kubectl commands.

With Helm, you can use the official WordPress chart from the Bitnami repository, which contains all the necessary templates and configuration values. You can install the chart with a single command: helm install wordpress bitnami/wordpress.

  • Updating an NGINX ingress controller:

Without Helm, you would need to download the latest YAML files from the NGINX ingress controller repository and apply them using kubectl commands.

You would also need to keep track of the changes and customizations that you made to the YAML files.

With Helm, you can use the official NGINX ingress chart from the Kubernetes stable repository, which allows you to update the ingress controller with a single command: helm upgrade nginx-ingress stable/nginx-ingress. You can also use a values file to customize the chart parameters.

  • Installing a Prometheus monitoring system:

Without Helm, you would need to create dozens of YAML files to define the Kubernetes resources for the Prometheus monitoring system, such as deployments, services, service monitors, alert managers, rules, and dashboards.

You would also need to manually apply each YAML file using kubectl commands.

With Helm, you can use the official Prometheus chart from the Prometheus community repository, which contains all the necessary templates and configuration values. You can install the chart with a single command: helm install prometheus prometheus-community/prometheus.

Helm can simplify the installation, upgrade, and management of complex applications on AKS. Helm can also help you share and reuse applications as charts, and manage application dependencies

Comparison, orchestrating Container without and with Helm?

ActivityWithout Helm    With Helm
Deploying a WordPress applicationCreate several YAML files and apply them manually using kubectl commandsUse the official WordPress chart from the Bitnami repository and install it with a single command: helm install wordpress bitnami/wordpress
Updating an NGINX ingress controllerDownload the latest YAML files from the NGINX ingress controller repository and apply them manually using kubectl commandsUse the official NGINX ingress chart from the Kubernetes stable repository and update it with a single command: helm upgrade nginx-ingress stable/nginx-ingress
Installing a Prometheus monitoring systemCreate dozens of YAML files and apply them manually using kubectl commandsUse the official Prometheus chart from the Prometheus community repository and install it with a single command: helm install prometheus prometheus-community/prometheus

 

Demo#Install Helm

Helm | Quickstart Guide

Demo# Develop AKS with Helm

Understanding Option1 (without Helm)

To know more about this, click here: Configure and deploy an app to Azure Kubernetes Services (AKS), without Helm Chart

 Option 2(using Helm)

Now, let’s explore Option2. Below are the high-level steps using this option.

In Option 2 we don’t need to do the steps followed in Option1

StepsStep DescOption1
(Without Helm)
Option2
(With Helm)    
Comments
Prepare appGet the app/Clone; Compose Docker File (means, create the container image, download redis image etc, and start the app local using Docker compose command.     docker compose -f docker-compose-quickstart.yml up -dYesYes 
Create ACRCreate Azure Container Registry, BUILD and PUSH the image to ACR   az acr build –registry $ACRNAME –image aks-store-demo/product-service:latest ./src/product-service/YesYes 
Create Helm ChartInstall Helm Chart 3.o Generate the Helm Chart:   helm create azure-vote-front   Update azure-vote-front/Chart.yaml to add a dependency for the redis chart from the https://charts.bitnami.com/bitnami and the appVersion to v1   Update the Helm Chart dependencies:   helm dependency update azure-vote-front   Update azure-vote-front/values.yaml;   Change image.repository to <loginServer>/azure-vote-front.     Add an env section to azure-vote-front/templates/deployment.yaml   YesThese 2 steps are additional if using Helm Chart. Adv. 
Run Helm ChartInstall your application using your Helm chart using the helm install  helm install azure-vote-front azure-vote-front/Yes 
Create AKSCreate AKS cluster;   az aks create \ –resource-group myResourceGroup \ –name myAKSCluster \ –node-count 2 \ –generate-ssh-keys \ –attach-acr <acrName>YesYes 
Run AppUpdate the image names in Kubernetes manifest file and include the ACR Login server name.   containers:  … – name: order-service  image: <acrName>.azurecr.io/aks-store-demo/order-service:latest And deploy the App by command kubectl apply -f aks-store-quickstart.yaml Test the app: kubectl get service store-front –watch   
Scale App/Upgrade  Appkubectl get pods kubectl scale –replicas=5 deployment.apps/store-front Autoscale Pods using Manifest file. spec:   maxReplicas: 10 # define max replica count   minReplicas: 3  # define min replica count   

Demo# Step by Step (Option2: using Helm)

1.       Git Clone

2.       Create an Azure Container Registry

az group create --name myResourceGroup --location eastus
 
az acr create --resource-group myResourceGroup --name myhelmacr --sku Basic

Create an AKS cluster

az aks create --resource-group myResourceGroup --name myAKSCluster --location eastus --attach-acr myhelmacr --generate-ssh-keys

3.       Connect to your AKS cluster

az aks install-cli 
 
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

4.       Download the sample application

git clone https://github.com/Azure-Samples/azure-voting-app-redis.git 
 
cd azure-voting-app-redis/azure-vote/ 

5.       Build and push the sample application to ACR

az acr build --image azure-vote-front:v1 --registry myhelmacr --file Dockerfile . 

6.       Create your Helm chart

helm create azure-vote-front 

Update azure-vote-front/Chart.yaml to add a dependency

apiVersion: v2
name: azure-vote-front
description: A Helm chart for Kubernetes

dependencies:
  - name: redis
    version: 17.3.17
    repository: https://charts.bitnami.com/bitnami

...
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: v1

EARLIER Code:

NEW Code:

And run below command!

helm dependency update azure-vote-front

Update azure-vote-front/values.yaml with the following changes.

Deployment code

Earlier Code

 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "azure-vote-front.fullname" . }}
  labels:
    {{- include "azure-vote-front.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "azure-vote-front.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "azure-vote-front.labels" . | nindent 8 }}
  {{- with .Values.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "azure-vote-front.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          {{- with .Values.volumeMounts }}
          volumeMounts:
            {{- toYaml . | nindent 12 }}
          {{- end }}
      {{- with .Values.volumes }}
      volumes:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

New Code:

...
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
          - name: REDIS
            value: {{ .Values.backendName }}
... 

7.       Run your Helm chart

helm install azure-vote-front azure-vote-front/
kubectl get service azure-vote-front --watch

When the service is ready, the EXTERNAL-IP value changes from <pending> to an IP address. Press CTRL+C to stop the kubectl watch process.

Output

  NAME               TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S)        AGE

  azure-vote-front   LoadBalancer   10.0.18.228   <pending>       80:32021/TCP   6s

  …

  azure-vote-front   LoadBalancer   10.0.18.228   52.188.140.81   80:32021/TCP   2m6s

8.       Delete the cluster

az group delete --name myResourceGroup --yes --no-wait

 Recap:

  1. Create an Azure Container Registry (ACR):
    • Use Azure CLI or Azure PowerShell to create a resource group and an ACR.
    • Ensure the registry name is unique and follows Azure naming conventions.
  2. Create an AKS Cluster:
    • Deploy an AKS cluster using Azure CLI or Azure PowerShell.
    • Configure the cluster with the necessary settings for your application.
  3. Connect to Your AKS Cluster:
    • Use the Azure CLI to establish a connection to your newly created AKS cluster.
  4. Package and Run an Application on AKS Using Helm:
    • Helm charts help you define, install, and upgrade even the most complex Kubernetes applications.
    • Package your application into a Helm chart and deploy it to your AKS cluster.

 Conclusion

Helm is a powerful tool that streamlines the deployment of applications on Kubernetes, particularly in an AKS environment.

By following this post, developers can efficiently manage the complexities of Kubernetes resources and focus on building robust applications.

With Helm, you can easily package, deploy, and manage your applications in AKS, making it an essential tool for any Kubernetes developer. 🚀🐳

References:

https://learn.microsoft.com/en-us/azure/aks/quickstart-helm?source=recommendations&tabs=azure-cli

https://learn.microsoft.com/en-us/azure/aks/quickstart-dapr?tabs=azure-cli

https://learn.microsoft.com/en-us/azure/aks/draft-devx-extension-aks

Leave a Reply

Discover more from Rajeev Singh | Coder, Blogger, YouTuber

Subscribe now to keep reading and get access to the full archive.

Continue reading