fbpx
How to Deploy Jenkins on Kubernetes

In this tutorial, we’ll go into detail about how to deploy Jenkins on Kubernetes using K3s, a streamlined Kubernetes distribution ideal for edge, IoT, and small clusters. To make the process as clear as possible, this guide will offer specific, step-by-step instructions and examples.

Jenkins and Kubernetes have proven to be essential tools in the DevOps space. Continuous integration and delivery (CI/CD) is provided by Jenkins, a top open-source automation server, while a powerful platform for container orchestration is provided by Kubernetes. These two can be combined to greatly simplify application deployment and management.

Prerequisites


To follow this guide, you should have:

Step 1: Add Jenkins Helm Chart Repository

The Jenkins Helm chart repository must be added as the first step in the deployment of Jenkins. The command listed below can be used to accomplish this:

helm repo add jenkinsci https://charts.jenkins.io

Once the repository is added, update it to ensure you have access to the latest charts:

helm repo update
How to Deploy Jenkins on Kubernetes

Step 2: Configure Jenkins on Kubernetes Deployment

Next, you’ll need to create a YAML file to define your Jenkins deployment. We’ll name this file jenkins-values.yaml. In this file, you’ll specify the parameters for your Jenkins on Kubernetes deployment:

controller:
  installPlugins:
    - kubernetes:1.28.6
    - workflow-job:2.40
    - workflow-aggregator:2.6
    - credentials-binding:1.24
    - git:4.4.5
  persistence:
    storageClass: local-path
    size: 8Gi
  serviceType: NodePort
  servicePort: 8080
  nodePort: 32000
  ingress:
    enabled: false
agent:
  volumes:
    - type: HostPath
      hostPath: /var/run/docker.sock
      mountPath: /var/run/docker.sock

This configuration details the ports to use, the storage class and size, the service type, and the plugins that need to be installed. Jenkins can talk to the Docker daemon through the HostPath volume.

Step 3: Deploy Jenkins on Kubernetes

You can now use the Helm chart to deploy Jenkins on Kubernetes after completing your configuration file:

helm install jenkins jenkinsci/jenkins --namespace jenkins --create-namespace --values jenkins-values.yaml
Deploy Jenkins on Kubernetes

This command deploys Jenkins in its own namespace.

Step 4: Access Jenkins

Run the following command to get the admin password after Jenkins has been deployed:

kubectl exec -it jenkins-0 -n jenkins --container jenkins -- /bin/cat /run/secrets/additional/chart-admin-password && echo
Jenkins on Kubernetes admin password

You need to expose the Jenkins service using a NodePort or a LoadBalancer. Since you were trying to access it on port 32000, we assume that you want to use a NodePort. Here’s how you can do it:

kubectl patch svc jenkins -n jenkins -p '{"spec": {"type": "NodePort", "ports": [{"port": 8080, "nodePort": 32000}]}}'

You can then access Jenkins by opening a web browser and navigating to http://:32000. Use admin as the username and the retrieved password for logging in.

Jenkins on Kubernetes web interface

Final Thoughts

It’s simple to deploy Jenkins on Kubernetes, which can greatly improve the efficiency of your CI/CD pipeline. You can navigate the process with the help of the step-by-step instructions in this guide. For the best results, remember to modify these guidelines to suit your unique requirements.

Continuous learning and experimentation are essential for mastering these tools, as they are for everything else in DevOps. Therefore, don’t be afraid to explore more and try out various configurations and plugins. Cheers to deployment!


1 Comment

How To Deploy ArgoCD On Kubernetes - Virtono Community · October 3, 2023 at 5:24 PM

[…] get started with deploying ArgoCD on Kubernetes. With the rise of containerization and orchestration technologies, Kubernetes has become the de facto standard for container management. When it comes to Continuous […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.