Setup Gitlab CI/CD pipeline for Kubernetes using Helm

In this blog, we will setup a Gitlab CI/CD pipeline for Kubernetes using Helm chart.

We will be deploying a sample Drupal application using Helm chart and deploy in GKE


  1. Create a git repo in gitlab
  2. Create a .gitlab-ci.yaml and values.yaml file
  3. Create Kubernetes cluster from Gitlab
  4. Connect to Kubernetes cluster using cloud shell
  5. Create ingress controller on the Kubernetes Cluster
  6. Validate the application on the browser

Git Repo

Image for post

Setup a GKE using gitlab

Go to your project in Gitlab and then

  1. Click on Operations -> Kubernetes
Image for post

Click on Connect Cluster with certificate

Image for post

Create a new cluster -> Select GKE option -> This will ask you to login to your google account

Image for post

Provide all the details

  • You need to create the project in Google cloud first and then in the dropdown it will show all the projects which exist in your Google account
Image for post
Image for post
Image for post

This will take around 5–10 minutes. You can validate in your GKE also to check if your cluster is ready or not

Connect to cluster

Login to your Google cloud account -> Kubernetes Cluster -> Select your cluster -> Click on Connect

Image for post


Image for post

You can copy the below command and run click on Activate cloud shell and paste this. If you will not run this command then your helm install will failed

Image for post
gcloud container clusters get-credentials gke-2 --zone us-central1-a --project kubernetes-cluster-298116
Image for post

Create ingress controller on the Kubernetes Cluster

For more details, click here

helm repo add nginx-stable 
helm repo update
helm install nginx-ingress nginx-stable/nginx-ingress
# Check that the ingress controller is installed successfully kubectl get service nginx-ingress-nginx-ingress
Image for post

Validate it on GKE — You can check that it has created a load balancer for you as shown below:

Image for post

Create a Gitlab Pipeline

Create a .gitlab-ci.yaml with the below content


environment: This tag is important and the value of this is what you have configured while creating a Kubernetes cluster. If you will not use this tag and the pipeline job will fail while making a connection to Kubernetes cluster as shown below

Image for post

We are using the shared runners which gitlab provides by default so we need to use other docker image where helm software is also installed. If you will not use the docker image then the pipeline will fail with the error helm command not found

- test

stage: test
image: devth/helm:latest
environment: production

- helm repo add bitnami
- helm repo update
- helm install druapltest3 bitnami/drupal -f values.yaml

Create a values.yaml file if you want to customize it. I have customize it for the ingress to be enabled

## Set to true to enable ingress record generation
enabled: true
hostname: drupal.local
path: /

Trigger the pipeline

Image for post

If you are doing the local testing then update the /etc/hosts file with the below content. You can get the ingressIp using `kubectl get ingress'

Image for post

Now access the url on the browser

Image for post

Devops Automation Enginneer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store