Setting up Jenkins on Google Kubernetes Engine with Helm

Rohan Singh
Oct 31, 2019 · 6 min read

After publishing my last blog — Jenkins on Google Compute Engine, I got a demand to write the same blog but with Google Kubernetes Engine via Helm.

We are doing it the same in our organization, and recently I’ve done it for a project in my organization, so here it is!

This blog is updated with Helm v3 in which we don’t need tiller and that extra configuration to setup.

Image for post
Image for post

Google Kubernetes Engine (GKE)

GKE is a perfect combination or I should say a blend of Iaas and PaaS making it as Kubernetes as a Service or Container as a Service which Google was using since 2003 as its internal orchestrator till 2015 when it gets open-source with a benefit of autoscaling of the cluster, integration of Stackdriver, fluentd, Prometheus, VPN etc. Kubernetes Engine enables rapid application development and iteration by making it easy to deploy, update, and manage our applications and services with no vendor lock-in which means you’re free to take your applications out of Kubernetes Engine and run them anywhere Kubernetes is supported, including on your own on-premises servers.

With containers, we just bundle our application code and its dependencies into a single unit which abstracts our application from any sort of infrastructure. Containers package our applications so they can run in any environment which might be UAT or production or staging. Container-based solutions give you the ability to manage applications.

Deploying Jenkins on Kubernetes Engine provides important benefits which don’t provide by standard VM-based deployment. When our build process uses containers, one virtual host can run jobs on multiple operating systems. Kubernetes Engine provides ephemeral build executors—these are only utilized when builds are actively running, which leaves resources for other cluster tasks such as batch processing jobs. Another benefit of ephemeral build executors is speed—they launch in a matter of seconds.

To start with this first we need to create a K8s cluster in GCP, to create run:

gcloud container clusters create jenkins-cluster \
--num-nodes 2 \
—-zone us-central1-a \
—-machine-type n1-standard-2 \
—-scopes “https://www.googleapis.com/auth/source.read_write,cloud-platform"

Cluster creation will take some time.

Run this command to view the cluster list:

gcloud container clusters list

Your output should look similar to this:

Image for post
Image for post

Now, get the credentials for your cluster:

gcloud beta container clusters get-credentials jenkins-cluster --region us-central1 --project [PROJECT_NAME]

You will get this command in GKE Console just by clicking Connect button.

Your output should look similar to this:

Fetching cluster endpoint and auth data.
kubeconfig entry generated for jenkins-cluster.

Now we are done with K8s cluster, it’s time to install the Helm. Yay!

Helm, Yay!!!!

Helm

In a very simple term — Helm is a package manager which automates the process of installing, configuring, upgrading, and removing complex Kubernetes application. This is what NPM is for Nodejs, Maven is for Java, Hombrew for Mac, Chocolatey for Windows is!

Not so deep concepts!

An application in Kubernetes typically consists of at least two resource types:

  • deployment resource — describes a set of pods to be deployed together
  • services resource — defines endpoints for accessing the APIs in those pods.

The application can also include ConfigMaps, Secrets, and Ingress.

For any deployment, you need several Kubernetes commands (kubectl) to create and configure resources. Basically it’s manually creating each resource separately which is painful. A Helm chart defines several Kubernetes resources as a set. Helm can make deployments easier and repeatable because all resources for an application are deployed by running one command.

A Chart is a Helm package. It contains all of the resource definitions necessary to run an application, tool, or service inside of a Kubernetes cluster. With Helm, configuration settings are kept in values.yaml file separate from the manifest formats. You can change the configuration values according to your application need without touching the rest of the manifest.

To install Helm(v3) in your cluster, run:

curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -sudo apt-get install apt-transport-https --yesecho "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.listsudo apt-get updatesudo apt-get install helm

To download your desired version, check Helm release page

To give yourself cluster administrator permission in the cluster’s RBAC, run:

kubectl create clusterrolebinding cluster-admin-role --clusterrole=cluster-admin --user=$(gcloud config get-value account)

Yay! we are done with Helm installation, now let’s move forward to install Jenkins

Jenkins

Jenkins is one of the most popular, free, open, Java coded CI/CD tool in the industry used by some big MNCs like Netflix, LinkedIn, eBay, Nintendo etc to small startups let flexibly orchestrate build, test, and deployment pipelines. Jenkins allows developers to iterate quickly on projects without worrying about overhead issues that can stem from continuous delivery. We integrate our Jenkins with source/version control system like Github, Gitlab, Bitbucket, and can execute Apache Ant, Apache Maven and sbt based projects as well as arbitrary shell scripts and Windows batch commands.

Run the following command to install Jenkins on Kubernetes cluster via Helm Chart by one shot:

helm repo add jenkinsci https://charts.jenkins.iohelm repo updatehelm install jenkins-tool jenkinsci/jenkins

It takes a couple of minutes to perform this step

To check running pods, run:

kubectl get pods

Your output looks like this:

Image for post
Image for post

Configure the Jenkins service account to be able to deploy to the cluster

kubectl create clusterrolebinding jenkins-deploy --clusterrole=cluster-admin --serviceaccount=default:jenkins-tool

Get your ‘admin’ user password by running:

printf $(kubectl get secret --namespace default jenkins-tool -o jsonpath=”{.data.jenkins-admin-password}” | base64 — decode);echo

Output like this will be shown:

Image for post
Image for post

Run below command to view service:

kubectl get svc

Your output will be like this:

Image for post
Image for post

Copy the External-IP:8080 and paste into your browser and Voila! Jenkins started. In signup page, enter admin in username and password you copied from 2nd last step.

This type page will come!!!

Image for post
Image for post

That’s how you set up Jenkins with GKE

Google Kubernetes Engine Docs

Kubernetes Docs

Jenkins Docs

Helm Docs

Helm Charts

Give it a clap, if you find it useful.

Image for post
Image for post

Follow us on Twitter 🐦 and Facebook 👥 and join our Facebook Group 💬.

To join our community Slack 🗣️ and read our weekly Faun topics 🗞️, click here⬇

Image for post
Image for post

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts

Sign up for FAUN

By FAUN

Medium’s largest and most followed independent DevOps publication. Join thousands of aspiring developers and DevOps enthusiasts Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Rohan Singh

Written by

Cloud Engineer @ Searce Inc | Living in ☁️ since Sept 2017 | https://rohankalhans.xyz

FAUN

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Rohan Singh

Written by

Cloud Engineer @ Searce Inc | Living in ☁️ since Sept 2017 | https://rohankalhans.xyz

FAUN

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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