Schedule jenkins slaves across all nodes in kubernetes cluster (round robin)

10/30/2019

my Kubernetes setup:

  • v1.16.2 on bare metal
  • 1 master node: used for Jenkins Master + Docker registry
  • 5 slave nodes: used for Jenkins JNPL slaves

I use kubernetes-plugin to run slave docker agents. All slave k8 nodes labeled as "jenkins=slave". When I use nodeSelector ("jenkins=slave") for podTemplate, kubernetes always schedule new pod on same node regardless the amount of started Jenkins jobs.

Please give me advice, how I can configure kubernetes or kubernetes-plugin to schedule each next build by round-robin (across all labeled nodes in kubernetes cluster)

Thank you.

-- Yaroslav Berezhinskiy
jenkins
jenkins-plugins
kubernetes

1 Answer

10/30/2019

This is generally handled by the inter-pod anti affinity configuration https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#inter-pod-affinity-and-anti-affinity. You would set this in the pod template for your builder deployment. That said, it's more common to use the Kubernetes plugin for Jenkins which runs each build as a temporary pod, rather than having long-lived JNLP builders.

-- coderanger
Source: StackOverflow