Setting up taints on pod template in Kubernetes Plugin on Jenkins

2/27/2018

I would like to apply the tolerations on the Jenkins slave pod that are dynamically spinned by the Kubernetes Plugin. I see that the Kubernetes Plugin does not provide any option on the Jenkins UI to add the tolerations, as shown in the image below. Could anyone tell me, how can I add the tolerations in this case to the slave pods(which are generated by kubernetes plugin).

P.S.:- I do not want to use labels,I Strictly want to use tolerations. And I am not sure if I want to add the podTemplate in the Jenkinsfile and specify the tolerations in this podTemplate. Because this will force me to do the same for every job's Jenkinsfile, which is tedious and not possible if multiple developers prepare their own respective pipelines.enter image description here

-- Suhas Chikkanna
jenkins
jenkins-pipeline
jenkins-plugins
kubernetes

3 Answers

3/5/2018

As far as I know and to this date, it is not possible to add tolerations to jenkins's slaves that are spinned up by the kubernetes plugin. And also in this case it is also not possible to add the tolerations in podTemplateSpec (podTemplateSpec - is an alternate option to define pod & Container template which is mentioned in the github repo of kubernetes plugin:- https://github.com/jenkinsci/kubernetes-plugin ) of the Jenkinsfile.

-- Suhas Chikkanna
Source: StackOverflow

8/13/2019

apiVersion: v1 kind: Pod metadata: labels: jenkins/kube-default: true app: jenkins component: agent spec: nodeSelector: jenkinsslave: jenkinsslave tolerations: - key: "efk_taint" operator: "Exists" effect: "NoSchedule"

-- lanni654321
Source: StackOverflow

10/16/2018

You can actually add taints to the configs in jenkins outright.

https://github.com/jenkinsci/kubernetes-plugin/pull/311#issuecomment-386342776

You can add this into the "raw yaml for the pod" under your container and update your criteria accordingly for the labels.

I have used this myself and it does indeed work.

(here's the yaml from the link above)

apiVersion: v1
kind: Pod
metadata:
  labels:
    jenkins/kube-default: true
    app: jenkins
    component: agent
spec:
  nodeSelector:
    werkint.com/entity: other
  tolerations:
  - key: werkint.com/entity
    operator: Equal
    value: other
    effect: NoSchedule
-- bek
Source: StackOverflow