Helm is a quick and easy way to deploy a webapp application instance on a kubernetes cluster with Helm chart. Follow the steps below.
Table of Contents
Deploy Webapp on Kubernetes Using with Helm Chart
This guide covers how you can install helm on kubernates cluster and get started using Helm chart for deploying a webapp application on kubernates cluster.
Prerequisites
You must have Kubernetes installed. For the latest release of Helm, we recommend the latest stable release of Kubernetes.
Also Read: What is Kubernetes? | Kubernetes explained
Step 1: Installing Helm From Script on Kubernetes
Helm has an installer script that will automatically grab the latest version of Helm and install it on kubernates locally.
You can fetch that script, and then execute it on kubernates locally.
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 $ chmod 700 get_helm.sh $ ./get_helm.sh
Step 2: Create the helmchart
$ helm create webapp
Step 3: Delete everything in templates folder
$ rm -r *
Step 4: Create the yaml files in templates folder
1. Create configmap.yaml with the following data
$ vim configmap.yaml apiVersion: v1 kind: ConfigMapĀ metadata: Ā Ā name: {{ .Values.configmap.name }} Ā Ā namespace: {{ .Values.namespace }} data: Ā Ā BG_COLOR: '#12181b' Ā Ā FONT_COLOR: '#FFFFFF' Ā Ā CUSTOM_HEADER: {{ .Values.configmap.data.CUSTOM_HEADER }}
2. Create deployment.yaml with the following data
$ vim deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: Ā Ā name: {{ .Values.appName }} Ā Ā namespace: {{ .Values.namespace }} Ā Ā labels: Ā Ā Ā Ā app: {{ .Values.appName }} spec: Ā Ā replicas: 1 Ā Ā selector: Ā Ā Ā Ā matchLabels: Ā Ā Ā Ā Ā Ā app: {{ .Values.appName }} Ā Ā Ā Ā Ā Ā tier: frontend Ā Ā template: Ā Ā Ā Ā metadata: Ā Ā Ā Ā Ā Ā labels: Ā Ā Ā Ā Ā Ā Ā Ā app: {{ .Values.appName }} Ā Ā Ā Ā Ā Ā Ā Ā tier: frontend Ā Ā Ā Ā spec: # Pod spec Ā Ā Ā Ā Ā Ā containers: Ā Ā Ā Ā Ā Ā - name: mycontainer Ā Ā Ā Ā Ā Ā Ā Ā image: "{{ .Values.image.name }}:{{ .Values.image.tag }}" Ā Ā Ā Ā Ā Ā Ā Ā ports: Ā Ā Ā Ā Ā Ā Ā Ā - containerPort: 80 Ā Ā Ā Ā Ā Ā Ā Ā envFrom: Ā Ā Ā Ā Ā Ā Ā Ā - configMapRef: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā name: {{ .Values.configmap.name }} Ā Ā Ā Ā Ā Ā Ā Ā resources: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā requests: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā memory: "16Mi"Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā cpu: "50m"Ā Ā # 50 milli cores (1/20 CPU) Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā limits: Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā memory: "128Mi" # 128 mebibytesĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā cpu: "100m"
3. Create service.yaml with the following data
$ vim service.yaml apiVersion: v1 kind: Service metadata: Ā Ā name: {{ .Values.appName }} Ā Ā namespace: {{ .Values.namespace }} Ā Ā labels: Ā Ā Ā Ā app: {{ .Values.appName }} spec: Ā Ā ports: Ā Ā - port: 80 Ā Ā Ā Ā protocol: TCP Ā Ā Ā Ā name: flask Ā Ā selector: Ā Ā Ā Ā app: {{ .Values.appName }} Ā Ā Ā Ā tier: frontend Ā Ā type: LoadBalancer
Step 5: Delete values.yaml fileĀ
$ rm values.yaml
Step 6: Create values.yaml file with the following data
$ vim values.yaml appName: myhelmapp namespace: default configmap: Ā Ā name: myhelmapp-configmap-v1 Ā Ā data: Ā Ā Ā Ā CUSTOM_HEADER: 'This app was deployed with helm!' image: Ā Ā name: devopsjourney1/mywebapp Ā Ā tag: latest
Step 7: Pull image
$ sudo docker pull devopsjourney1/mywebapp:latest
Step 8: Install the first one
$ helm install webapp-release webapp/ --values webapp/values.yaml
Step 9: The helm list (or helm ls) function will show you a list of all deployed releases
$ helm list
Step 10: Upgrade after templating
$ helm upgrade webapp-release webapp/ --values webapp/values.yaml
Step 11: Uninstall webapp application
To uninstall a release, use the helm uninstall command:
$ helm uninstall webapp-release
Also Read: How To Install and Use Docker on Ubuntu 22.04
Be the first to comment