Kubernetes Jenkins plugin - slaves always offline

When running jenkins in Kubernetes, the service name is resolvable by both the jenkins master and slaves.

The best way to configure this is than the use the internal DNS and set the jenkins url to:

http://jenkins:8080

(assuming you called your service jenkins, and your port on the service is 8080)

No tunnel is required.

The benefit of this approach is that it will survive restarts of your jenkins without reconfiguration.

Secondary benefit is that you would not have to expose Jenkins to the outside world, thus limiting security risks.


I just want to add a bit more explanation to the above answers for newbies.

While exposing the jenkins UI, you also need to expose internal port 50000 Here is a simple service for a jenkins deployment:

apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
spec:
  type: NodePort
  ports:
    - port: 8080
      name: "http"
      nodePort: 30000
      targetPort: 8080
    - port: 50000
      name: "slave"
      nodePort: 30010
      targetPort: 50000
  selector:
    app: jenkins

For external access to the Jenkins UI, nodePort is being used in the above configuration. I'm exposing port 8080 to the nodePort 30000 (jenkins UI will now available at node_ip:30000) and exposing pod port 50000 to nodeport 30010.

Once the svc is created:

$ kubectl get svc -n jenkins
NAME      CLUSTER-IP    EXTERNAL-IP   PORT(S)                          AGE
jenkins   10.233.5.94   <nodes>       8080:30000/TCP,50000:30010/TCP   23m

Now add jenkins_ip:30010 as Jenkins Tunnel.


You need to expose both port 8080 and 50000 as described in the plugin example config https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/kubernetes/jenkins.yml


Thanks to @csanchez I have the solution.

enter image description here

The problem was that I am running the jenkins server in k8 and I didn't specify a fixed port in k8 (I let k8 pick the port). So changing the config for the jenkins tunnel solved it.

A better solution is to have the port be fixed as suggested, making that change next.