Setting up Jenkins on Google Kubernetes Engine

This tutorial shows you how to set up Jenkins on GKE to help orchestrate your software delivery pipeline.


  • Creating a Kubernetes cluster with GKE.
  • Installing Jenkins using Helm.
  • Connecting to Jenkins.


This tutorial uses billable components of Google Cloud, including:

  • Compute Engine
  • Google Kubernetes Engine
  • Cloud Build

Use the Pricing Calculator to generate a cost estimate based on your projected usage. New Google Cloud users might be eligible for a free trial.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.

  4. Enable the Compute Engine, GKE, and Cloud Build APIs.

    Enable the APIs

Preparing your environment

First, prepare your deployment environment.

  1. Activate Cloud Shell. Cloud Shell gives you access to the command line in Cloud Console, and includes Cloud SDK and other tools you need for Google Cloud development. Cloud Shell can take several minutes to provision.

    Activate Cloud Shell

    After the process completes, you'll see the following output:

    Welcome to Cloud Shell! For help, visit
  2. Set the default Compute Engine zone to us-east1-d:

    gcloud config set compute/zone us-east1-d
  3. Clone the sample code, or download the zip file.

    git clone

    The Git repository contains Kubernetes manifests that you'll use to deploy Jenkins. The manifests and their settings are described in Configuring Jenkins for GKE.

  4. Navigate to the sample code directory:

    cd continuous-deployment-on-kubernetes

Creating a Kubernetes cluster

You can use GKE to create and manage your Kubernetes cluster.

  1. Provision a Kubernetes cluster using GKE. This step can take up to several minutes to complete.

    gcloud container clusters create jenkins-cd \
      --machine-type n1-standard-2 --num-nodes 2 \
      --scopes ",cloud-platform" \
      --cluster-version 1.15

    The extra scopes enable Jenkins to access Cloud Source Repositories and Container Registry.

  2. Confirm that your cluster is running.

    gcloud container clusters list

    Look for RUNNING in the STATUS column.

    jenkins-cd  us-east1-d  1.15.11-gke.15  n1-standard-2  1.15.11-gke.15   2          RUNNING
  3. Confirm that you can connect to your cluster.

    kubectl cluster-info

    If you are able to successfully connect to your cluster, Kubernetes component URLs display.

    Kubernetes master is running at
    GLBCDefaultBackend is running at
    Heapster is running at
    KubeDNS is running at
    Metrics-server is running at

Installing Helm

Use Helm to deploy Jenkins from the repository.

  1. Download and install the Helm binary:

  2. Unzip the file to your local system:

    tar zxfv helm-v3.2.1-linux-amd64.tar.gz
    cp linux-amd64/helm .
  3. Add yourself as a cluster administrator in the cluster's RBAC so that you can give Jenkins permissions in the cluster:

    kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin \
            --user=$(gcloud config get-value account)
  4. Add the official stable repository:

    ./helm repo add jenkinsci
    ./helm repo update
  5. Ensure Helm is properly installed by running the following command:

    ./helm version

    You will see versions appear for the client as v3.2.1:

    version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}

Installing Jenkins

You will use a custom values file to configure the Jenkins installation. For details on the configuration, look at the jenkins/values.yaml file.

  1. Use the Helm CLI to deploy the chart with your configuration set:

    ./helm install cd-jenkins -f jenkins/values.yaml jenkinsci/jenkins --version 2.6.4 --wait

    For more information on configuring the Jenkins installation, visit the Jenkins chart's documentation page.

  2. After that command completes, ensure the Jenkins pod goes to the Running state and the container is in the READY state:

    kubectl get pods

    You will see 1/1 in the READY column and Running in the STATUS column. It can take a few minutes for Jenkins to complete its initialization.

    NAME                          READY     STATUS    RESTARTS   AGE
    cd-jenkins-7c786475dd-vbhg4   1/1       Running   0          1m
  3. Set up port forwarding to the Jenkins UI from Cloud Shell:

    export POD_NAME=$(kubectl get pods --namespace default -l "" -l "" -o jsonpath="{.items[0]}")
    kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
  4. Check that the Jenkins Service was created properly.

    kubectl get svc

    Example Output:

    NAME               CLUSTER-IP     EXTERNAL-IP   PORT(S)     AGE
    cd-jenkins   <none>        8080/TCP    3h
    cd-jenkins-agent    <none>        50000/TCP   3h
    kubernetes    <none>        443/TCP     9h

The Jenkins installation is using the Kubernetes Plugin to create builder agents. They will be automatically launched as necessary when the Jenkins master needs to run a build. When their work is done, they are automatically terminated and their resources are added back to the cluster's resource pool.

Connecting to Jenkins

  1. Retrieve the admin password that was automatically created by the Jenkins Helm chart:

    printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
  2. To open the Jenkins user interface, click Web Preview in Cloud Shell and click Preview on port 8080.


  3. Click log in on the top right of the window. Enter admin for the User field and the password value from the previous step for the Password field.

  4. Click the log in button.

You now have access to Jenkins and a Kubernetes cluster managed by GKE. To take this solution further, you could use these components in your continuous delivery pipeline.

Cleaning up

After you've finished the tutorial, clean up the resources you created on GCP so you won't be billed for them in the future.

Deleting the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

  1. In the Cloud Console, go to the Manage resources page.

    Go to the Manage resources page

  2. In the project list, select the project that you want to delete and then click Delete .
  3. In the dialog, type the project ID and then click Shut down to delete the project.

Deleting disks

  1. In the Cloud Console, go to the Disks page.

    Go to the Disks page

  2. Click the checkbox for your jenkins-home disk.
  3. Click Delete to delete the disk.

Deleting instances

To delete a Compute Engine instance:

  1. In the Cloud Console, go to the VM Instances page.

    Go to the VM Instances page

  2. Click the checkbox for the instance you want to delete.
  3. Click Delete to delete the instance.

What's next