Kubernetes Deployment Using Helm [Part 1]

In this article, We are going to cover Kubernetes Deployment Using Helm and GitLab CI CD Pipeline

Introduction

Recently we have added Helm in our Kubernetes deployment using GitLab CI CD pipeline. We were facing maintaining Version latest tag for every docker container.

Using Helm we can deploy microservice with same version and rollback  

What is Helm Chart in Kubernetes ?

Helm is free and open source package and operations manager tool for Kubernetes like npm and packaging format in the form of charts.

A chart is collection of files, folders and folders which is used for deploy any application on Kubernetes.

Why is the use of Helm in Kubernetes ?

  •  To Install packages and application
  • Automated versioning history of your microservice/application and rollback if any issues.
  • All helm charts are stored in each application registry called workspace
  • Easy for DevOps Team and SRE
  • Deployment process is more easy and efficient

Install Helm on Kubernetes

Install helm on Kubernetes Master node OR if you using Kubernetes KOPS then Install on Management Instance.

sudo wget https://get.helm.sh/helm-v2.16.8-linux-amd64.tar.gz
sudo tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/helm
sudo snap install helm --classic

Install tiller service on Kubernetes Cluster and create service account tiller

kubectl -n kube-system create serviceaccount tiller

Create Cluster Role Binding to access the tiller account

kubectl create clusterrolebinding tiller \
  --clusterrole=cluster-admin \
  --serviceaccount=kube-system:tiller

Use helm to Install the tiller service account

helm init --service-account tiller

Here we are going to create deployment.yml and service.yml using Helm

First clone your project’s Repository into local. Here we are using GitLab Runner to build the project

git clone repo name

Navigate to Repository folder path , here we have test-service repo

cd repo_path

Here we have microservice service name test-service

Lets create Helm chart workspace for microservice

helm create test-service
cd test-service/

You will see like below folders and charts

Output:

Chart.yaml  charts  templates  values.yaml

Navigate to templates folder

cd templates

Open the deployment.yml

sudo  nano deployment.yaml

Kubernetes Deployment Using Helm

Here is our Kubernetes deployment , please modify as per your microservice

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-service-deployment
  namespace: fosstechnix
  labels:
    app: test-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-service
  template:
    metadata:
      labels:
        app: test-service
    spec:
      containers:
        - name: test-service-container
          image: Docker_Container OR AWS_ECR_URI/test-service:latest
          ports:
            - containerPort: 8001

Next create Kubernetes Service

sudo nano service.yaml
apiVersion: v1
kind: Service
metadata:
  name: test-service
  namespace: fosstechnix
  labels:
    app: test-service
spec:
  selector:
    app: test-service
  ports:
  - port: 80
    targetPort: 8001

Next follow below article to Create CI CD Pipeline in GitLab to Deploy to Kubernetes using Helm and GitLab

Deploy to Kubernetes using Helm and GitLab [Part 2]

Conclusion

In this article, We have covered Kubernetes Deployment Using Helm

Related Articles

7 Steps for GitLab Runner Registration

Reference

Helm Official Page

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

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

Share via
Copy link
Powered by Social Snap