The latest cloud infrastructure announcements, technical solutions, and enterprise cloud insights.

Deploy Jenkins on Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE)

Abhiram Annangi
Principal Product Manager - Cloud Marketplace

In my previous blog post, I demonstrated how to deploy Jenkins in a master/slave architecture on Oracle Cloud Infrastructure by using the Oracle Cloud Infrastructure Compute plugin for Jenkins. This plugin enables you to spin up virtual machine (VM) or bare metal instances as slaves/agents on-demand within Oracle Cloud Infrastructure and then tear them down automatically after the job is complete. By spinning up a large number of agents, Jenkins can run many jobs in parallel.

As an alternative to using the VM-based plugin, you can instead create container-based Jenkins agents, which can be spun up more quickly than VMs (seconds versus minutes) and can be torn down quickly after the build job is complete. Jenkins container-based agents are provisioned based on a Docker container image with all the tools and environment settings that you need.

In this blog post, I'll demonstrate how to set up Jenkins agents as Docker containers and deploy them within a Kubernetes cluster in a few steps. I'll use a different plugin for Jenkins to accomplish this: the Kubernetes plugin for Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE). OKE delivers secure, highly available Kubernetes clusters and manages containerized applications on Oracle Cloud Infrastructure. Following the steps in this blog post, you can create a Jenkins deployment as shown in the following figure:


Step 1: Install the Kubernetes Plugin for Jenkins

The Kubernetes plugin for Jenkins is used to run dynamic Jenkins agents in a Kubernetes cluster.

  1. On the Jenkins Dashboard, click Manage Jenkins and then click Manage Plugins.
  2. On the Available tab, search for the Kubernetes plugin and install it without restarting.

Step 2: Configure the Kubernetes Plugin with OKE

  1. In the Jenkins Dashboard, click Manage Jenkins and then click Configure System.
  2. Click Add a new cloud, and choose Kubernetes.

  3. Go to the Kubernetes cloud configuration section and enter the following information:
    • Name: The name of the Kubernetes cloud configuration.
    • Kubernetes URL: The OKE cluster endpoint. You can obtain the Kubernetes URL by running the following command (assuming you already downloaded the kubeconfig file):

    • Kubernetes server certificate key: The X509 PEM encoded certificate. This is an optional parameter if you select Disable https certificate check. You can obtain the Kubernetes secret token by running the following command (assuming you already downloaded the kubeconfig file):

    • Kubernetes namespace: The namespace of the Kubernetes cluster.
    • Credentials: The secret text that stores your Kubernetes secret token. You can obtain the Kubernetes server certificate key in your kubeconfig file. Be sure to base64 decode it.
  4. Configure Kubernetes role-based access control (RBAC) to enable the default service account token to interact with the cluster by giving it the admin role:

  5. Click Test Connection and ensure that the response is “Connection test successful,” as shown in the following screenshot:

    Note: Occasionally, an error message stating “No valid crumb was included in the request” is displayed. This error is a bug in the Jenkins Kubernetes plugin. To fix the error, go back to the previous page and retry.
  6. Configure the Jenkins URL by entering your Jenkins Master URL. You can use the default values for the rest of the fields.

  7. Configure the Kubernetes Pod Template as shown in the following screenshot. Remember the label that you set for Jenkins agents because you will need it later when running the build jobs.

  8. Configure the Container Template as shown in the following screenshot. For the purpose of this blog post, we are using Oracle Container Registry as the source to pull a custom Jenkins jnlp-slave docker image. Ensure that the Jenkins jnlp-slave docker image is already available in the registry. You can also use the public Docker Hub registry to pull in the Jenkins jnlp-slave image, in which case you enter jenkins/jnlp-slave in the Docker image field. Save the configuration.


  • I marked the repository in Oracle Container Registry as public to be able to pull the custom jnlp-slave docker image. If you are using a private repository, configure Jenkins with the right credentials to access the repository.
  • If you are using public Docker Hub registry to pull the jnlp-slave image, be sure to enter jenkins/jnlp-slave. Many online resources indicate to enter jenkinsci/jnlp-slave, but it is being deprecated.

Step 3: Test the Kubernetes Plugin with OKE

  1. Create a simple project in Jenkins by clicking New and selecting Freestyle project.
  2. Name the project testOKE, and use the default values. In the Label Expression field, enter k8s, which we used it in the preceding configuration. Build the project.

    After the build starts, the jnlp-slave container is provisioned on the Jenkins Dashboard.
  3. Check the status by running the following commands:

This completes the deployment of Jenkins agents on Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE).

Extending the Deployment

In the preceding deployment, we ran the Jenkins master as a VM and scaled out Jenkins agents/slaves as Docker containers on the Container Service for Kubernetes (OKE). We can extend this deployment by deploying the Jenkins master inside the Kubernetes cluster, alongside the Jenkins slaves. This configuration provides fault tolerance for Jenkins containers (both master and slaves), service resiliency, and better resource utilization. Let’s look at how to achieve this in a few steps. The deployment looks similar to the setup shown in the following figure:


  • A Kubernetes cluster already deployed in Oracle Cloud Infrastructure.


The deployment of the Jenkins master in Kubernetes includes the following steps:

  1. Prepare the Kubernetes manifest files for Jenkins.
  2. Deploy the Jenkins master along with a Persistent Volume (PVC) on Oracle Cloud Infrastructure Block Volume.
  3. Expose the Jenkins service through a load balancer.
  4. Configure the Jenkins master.

Step 1: Prepare the Kubernetes Manifests for Jenkins

The jenkins-master.yaml manifest file contains the deployment configuration for the Jenkins master, which creates a single replica. We'll useg the latest Jenkins image in this setup while exposing ports 8080 and 50000 on Jenkins master containers. The jenkins-dir volume mount is associated with the PVC called jenkins-master-pvc.

The jenkins-pvc.yaml file consists of a PVC configuration that includes Oracle Cloud Infrastructure block volumes. We'll reserve a 50-GB block volume, which will be used to store Jenkins build files and artifacts, if needed.

Step 2: Deploy to the Kubernetes Cluster

Store the manifest files in a directory (for example, jenkins-k8s) and run the following command to create a Jenkins master deployment with a PVC:

Verify that the deployment and pod are created:

Verify that the PVC is created, either by running the following command or going to the Block Volumes section of the Oracle Cloud Infrastructure Console:

Step 3: Expose the Deployment via a Load Balancer

Now that the deployment is created, we can create a service and expose it via an Oracle Cloud Infrastructure load balancer on port 80 while setting the target port to 8080 (the Jenkins master listens on 8080 by default).

You can see that the load balancer is provisioned on the Oracle Cloud Infrastructure Console. After it is provisioned, it will have a public IP address exposed with port 80 as the listener.

You can verify the public IP address of your service by running the following command:

Step 4: Configure the Jenkins Master

Access the Jenkins dashboard on the public IP address that we obtained in step 3, on port 80. You should see the following screen:

Run the following commands to get the initial admin password for Jenkins.

After this, the process of configuring the Jenkins master is similar to what I illustrated in my previous blog post on deploying Jenkins on Oracle Cloud Infrastructure. After configuring the master, you can install the Kubernetes plugin and scale out the Jenkins slaves as illustrated in the first part of this post.

Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE) offers seamless integration of the Jenkins Kubernetes plugin. Configuring OKE on Jenkins Kubernetes plugin is similar to configuring other Kubernetes engines. OKE delivers secure, highly available Kubernetes clusters and manages containerized applications on Oracle Cloud Infrastructure.

Abhiram Annangi | Twitter  LinkedIn

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha