How To Use Kubernetes Pods As Jenkins Agents

Ertuğrul Şen
4 min readSep 4, 2022

--

In another post, I have explained how to setup Jenkins On Kubernetes Cluster, you can read it.

Let’s understand how this setup works.

  1. When we add Jenkins Kubernetes plugin, it will make an API call to create a Kubernetes agent pod.
  2. Jenkins create some agent in kubernetes which uses jnlp method and talks to them.

Jenkins Kubernetes plugin does all these processes for us from Jenkins to the Kubernetes so I want to share with you how to make these settings on jenkins.

First of all, You need to install Jenkins kubernetes plugin to integrate Jenkins, you can click to Manage Jenkins > Manage Plugins and click on the “Available” tab then you can enter Kubernetes in the search box.

After installation, you can go to “Configure Clouds” under Manage Jenkins. you can see “Cloud” to add new cloud drop-down, click on Kubernetes and add a new cloud.

Now let’s see how do I fill the settings, you should enter your Kubernetes servers IP for Kubernetes URL and Jenkins URL, you can find out the ip information by looking at the jenkins pod detail.

kubectl describe pod jenkins-7dcc9f96d8-t74c9 — namespace jenkins

kubectl describe pod

You need to disable https certificate check so you can click it. There are two more important fields that is namespace information and credentials. I created a namespace called jenkins, when I setup the jenkins application. we need to create secret text token as the credentials from the drop-down, the secret text should be the kubeconfig file located in local machine.

Jenkins Configure Kubernetes Clouds

You can test the connectivity to your Kubernetes cluster by clicking on the “Test Connection” button.

Labels are a type of metadata in Kubernetes that take on the form of a key-value. I enter “jenkins” in the key part and “agent” in the value part.

you need to add the Pod template with the details. The label is “kubelabel” will use this name, when describing the job.

The other configuration is the container template. If you don’t add a container template, the Jenkins Kubernetes plugin will use the default JNLP image from the Docker hub to pull this image “jenkins/inbound-agent”.

I added a maven image located in my docker hub is called “19912508/maven-agent:0.0.1” because I can build a maven application so I have a maven image. For now, I keep all this configuration.

yes, you can go to Jenkins main page and clicking on the new item, add a new pipeline job then I write simple script pipeline for the runing new example. Now we are ready, I can get a build on jenkins.

You should see a pending agent in the job build history. In a couple of minutes because it may take some time to start because it will try to download the image from docker hub then you will see a successful build.

Thank you.

Ertuğrul Şen

--

--

Responses (1)