Jenkins multi instances on kubernetes

Does anyone implement multi instances of jenkins on kubernetes.

  • each jenkins master is a pod
  • all URL are manage by ingress-nginx

I found a lot of example about one instance but not several instance on the same kubernetes cluster

Since jenkins reads and writes to memory and disk is not designed for ruining multiple controllers in parallel.
Generally you scale agents not the controller.

There is the jenkins runner project that let’s you run jenkins headless which might be what you want?

2 Likes

I have 31 Jenkins master’s that each one is on separate server (VM) with deferent IP and under docker-compose. the Jenkins slave are Dynamic VM’s.
I want to move all Jenkins Master to Kubernetes platform (1 cluster) and deploy them as pods.
the Jenkins slave at first will continue to be the dynamic VM’s and later on will be a pods.
My problem - already deploy 2 pods of Jenkins master but got problems when publish them threw Ingress Controller (Ingress-nginx).

My question was : I found a lot of example to deploy 1 pod (instance) of Jenkins master but didn’t find example of more then one Jenkins master pod/instance that deploy on kubernetes cluster

Hello @snup67 and welcome to this community :wave:

Please note that the terms “master” and “slaves” have been deprecated since 2016. Please refer to On Jenkins Terminology Updates for more details.
We request you update your post.

To me, it is possible to run multiple instances of Jenkins on Kubernetes. Each Jenkins controller can be deployed as a separate pod in the Kubernetes cluster. You can use Kubernetes StatefulSets to manage these pods.

To set up multiple Jenkins controllers in a Kubernetes cluster, you can follow these general steps:

  1. Define the Jenkins Docker image and configure it to include any required plugins and configurations.
  2. Define the Kubernetes Deployment and Service objects for each Jenkins controller pod. The Deployment object is responsible for creating and updating the pods, while the Service object is used to expose the pods to the network.
  3. Configure the Kubernetes Ingress object to route incoming requests to the correct Jenkins controller pod based on the URL.
  4. Configure any necessary persistent storage for the Jenkins controllers, such as Kubernetes PersistentVolumes or cloud-based storage solutions.
  5. Optionally, you can set up a load balancer to distribute incoming requests across multiple Jenkins controller pods.

Here is an example YAML configuration file for deploying a Jenkins controller pod:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins-controller
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins-controller
  template:
    metadata:
      labels:
        app: jenkins-controller
    spec:
      containers:
      - name: jenkins
        image: my-jenkins-image:latest
        ports:
        - containerPort: 8080
        - containerPort: 50000
        volumeMounts:
        - name: jenkins-home
          mountPath: /var/jenkins_home
      volumes:
      - name: jenkins-home
        persistentVolumeClaim:
          claimName: jenkins-pvc

You can deploy multiple instances of this Deployment object with different names and configurations to create multiple Jenkins controller pods.

Once you have deployed the Jenkins controller pods, you can configure the Kubernetes Ingress object to route incoming requests to the correct pod based on the URL. Here is an example YAML configuration file for the Ingress object:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: jenkins-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: jenkins.example.com
    http:
      paths:
      - path: /jenkins(/|$)(.*)
        backend:
          serviceName: jenkins-controller
          servicePort: 8080

This configuration routes all requests to http://jenkins.example.com/jenkins to the Jenkins controller pod with the name jenkins-controller on port 8080.

By deploying multiple instances of the Deployment and Service objects, and configuring the Ingress object to route requests to the appropriate pod, you can deploy multiple Jenkins controllers in a Kubernetes cluster.

1 Like

that what I have done , just add another instance in same ingress as path

1 Like

Hi @poddingue

The different names here you mean the name of the deployment? or the name of the containers? I don’t know if I need to increase the num of replicas or create multiple deployment.