How to Install Jenkins on Kubernetes Cluster

March 3, 2020


Jenkins is a continuous integration tool that automates a large portion of the software development process. Several development teams working on multiple projects in a complex microservices environment can be a strain on limited resources. Jenkins helps you deliver a flawless final product on schedule.

This tutorial will show you how to install Jenkins on a Kubernetes cluster.

article on installing jenkins on kubernetes cluster


  • Access to a command line/terminal
  • Kubernetes cluster
  • A fully configured kubectl command-line tool on your local machine

Installing Jenkins on Kubernetes Cluster

A Kubernetes cluster adds a new automation layer to Jenkins. Kubernetes makes sure that resources are used effectively and that your servers and underlying infrastructure are not overloaded.

Kubernetes’ ability to orchestrate container deployment ensures that Jenkins always has the right amount of resources available.

The example below shows you how to use a set of YAML (Yet Another Markup Language) files to install Jenkins on a Kubernetes cluster. The .yaml files are easily tracked, edited, and can be reused indefinitely.

Note: The YAML files in this article illustrate the Jenkins deployment process. They should not be used in a production environment without modifying them to accommodate for your clusters’ specific settings and network resources.

Create a Namespace for the Jenkins Deployment

A distinct namespace provides an additional layer of isolation and more control over the continuous integration environment. Create a namespace for the Jenkins deployment by typing the following command on your terminal:

kubectl create namespace jenkins

The name of the namespace should be a DNS compatible label. In this example, we named it jenkins.

successfully created the jenkins namespace

Use the following command list existing namespaces:

kubectl get namespaces

The output confirms that the jenkins namespace was created successfully.

list of existing namespace on the Kubernetes master node

Create Jenkins Deployment File

Once we have a designated namespace, use your preferred Linux text editor to create a jenkins-deployment.yaml file.

The deployment file in this example utilizes the jenkins/jenkins:lts Docker image and creates 1 replica that is going to be exposed on port 8080.

apiVersion: extensions/v1beta1
kind: Deployment
  name: jenkins-deployment
  replicas: 1
      app: jenkins
        app: jenkins
      - name: jenkins
        image: jenkins/jenkins:lts
        - containerPort: 8080
          - name: jenkins-home
            mountPath: /var/jenkins_home
        - name: jenkins-home
          emptyDir: {}

The volumeMounts section of the file creates a Persistent Volume. The role of a persistent volume is to store basic Jenkins data and preserve it beyond the lifetime of a pod. Exit and save the changes once you add the content to the Jenkins deployment file.

Note: In a production cluster, you would not use hostPath. Instead, a cluster administrator would provision a network resource such as the Amazon Elastic Block Store volume, or the Google Compute Engine persistent disk.

Deploy Jenkins

Use the newly created file to deploy Jenkins:

kubectl create -f jenkins-deployment.yaml --namespace jenkins

The command also instructs the system to install Jenkins within the jenkins namespace.

Create and Deploy Jenkins Service

Kubernetes manages the lifecycle of a pod within the cluster. It regularly removes and deploys pods to attain the desired state and to balance workloads. A Service is an abstraction that exposes Jenkins to the wider network. It allows us to maintain a persistent connection to the pod regardless of the changes taking place within the cluster.

Create a service with a jenkins-service.yaml file by using a text editor to add the following content:

apiVersion: v1
kind: Service
  name: jenkins
  type: NodePort
    - port: 8080
      targetPort: 8080
      nodePort: 44000
    app: jenkins

Tag the jenkins namespace and create the Service by entering the following command:

kubectl create -f jenkins-service.yaml --namespace jenkins

You are now able to access the Jenkins dashboard.

Access Jenkins Dashboard

Go to your browser and access a node by using its IP and the port you defined in the Service file.

For example:


To access Jenkins, you initially need to enter your credentials. The default username for new installations is admin. The password can be obtained in several ways. This example uses the Jenkins deployment pod name. To find the name of the pod, enter the following command:

kubectl get pods --namespace jenkins

Once you locate the name of the pod, use it to access the pod’s logs.

kubectl logs jenkins-deployment-45345423412-k9003 --namespace jenkins

The password is at the end of the log formatted as a long alphanumerical string.

displaying the location of the Jenkins password in the log file

You have successfully installed Jenkins on your Kubernetes cluster and can use it to create new and efficient development pipelines.

example screenshot of Jenkins dashboard

How Does Jenkins Work? (Bonus Explanation)

Jenkins has become an industry standard for automating software development pipelines. Before the concept of continuous integration, the development process was often hampered by complex integrations and lengthy testing procedures. Discovering flaws in the code at a later stage would often break the build and delay software releases.

A continuous integration DevOps tool provides rapid assessments of the quality of the code in the early stages of development. Developers can use this information to make necessary changes, repeating the process until they create an error-free product.

Jenkins is a self-contained solution, compatible with hundreds of integration plugins, forming a comprehensive and easy-to-use environment.

An overview of a basic Jenkins server setup.

Developers commit code to a repository. A CI server (Jenkins) regularly listens to changes made on the source code repository. Jenkins then builds the source code instance and generates a deployable artifact. The build process includes code quality assurance tests and security checks.

Jenkins uses plugins, like SonarQube, to produce detailed metrics of the quality assurance and build process. If the build fails, the information and the reasons for the failed test are presented to the developer to make additional changes to the submitted code.

This continuous loop results in a well-polished product. Jenkins creates a ready-to-deploy JAR package that can progress to the next phase of development/production.


Now you know how to install Jenkins on a Kubernetes cluster. Jenkins can automate many tasks and help developers submit code efficiently and consistently. Your developers are far more productive and no longer need to waste time by manually running local builds and tests.

Was this article helpful?
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
How to Install Jenkins on Ubuntu 18.04
April 23, 2020

Learn how to install Jenkins on Ubuntu 18.04. This software package is used to automate parts of the build...
Read more
How to Set Up and Run Kafka on Kubernetes
February 12, 2020

Kafka collects and structures vast amounts of data from multiple clients simultaneously. It's a great...
Read more
Introduction to Kubernetes Persistent Volumes
January 27, 2020

Persistent Volumes are used in Kubernetes orchestration when you want to preserve the data in the volume even...
Read more
6 Kubernetes Security Best Practices: Secure Your Workloads
January 23, 2020

This article presents basic security principles such as defense-in-depth and restricted privilege. Learn how...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.