Kubernetes Jenkins Plugin concurrent slaves not working

3/26/2018

I am on Jenkins 2.73.2.1 and using Kubernetes-jenkins plugin 1.4 to spin up dynamic slaves . However ,I am not able to start up parallel builds. Jenkins always puts it to build queue and executes one at a time.

I have tried setting this while starting jenkins but it doesn't help either:

-Dhudson.slaves.NodeProvisioner.initialDelay=0
-Dhudson.slaves.NodeProvisioner.MARGIN=50
-Dhudson.slaves.NodeProvisioner.MARGIN0=0.85

Is there any other setting we have to do at plugin configuration end for parallel pods running ?

-- swetad90
jenkins
kubernetes

2 Answers

3/27/2018

The solution that worked for us was combination of above JVM arguments as well as selecting "use jobs matching the current label only" in kubernetes container template section.

We were able to run the required jobs parallelly in different pods

-- swetad90
Source: StackOverflow

1/26/2019

You have to configure the following parameters correctly in order to run slave concurrently and as per your expectation :

Under Kubernetes Pod Template,

1) Set Labels for Pod template correctly.

  • Make sure you have Jenkins Job with the same label configured.
  • In that jenkins job's configuration, mark Restrict where this project can be run and provide the same label as you provided in Labels field of Jenkins Configuration.

2) Set Max number of instances. This parameter will tell Jenkins How many maximum slaves it can launch with the given label

3) Set Time in minutes to retain agent when idle. This parameter will tell Jenkins Till how much time to retain slave (with the given label) on which no build is running.

  • Correctly configuring this will save you from Kubernetes Pod Creation time.
  • Make sure Pod Retention policy is Default.

Under Cloud section,

1) Set Container Cap. This parameter will tell Jenkins How many slaves can be spawned on Kubernetes.

  • This is limit on the total number of Pods that Jenkins can create on Kubernetes cluster.
  • This limit applies cumulatively to all labels.
  • Hence, if Max number of instances is greater than Container Cap. Jenkins will only be able to create slaves equal to Container Cap for the label at best.
  • So ideally keep Container Cap equal to Sum of (Max number of instances) of all labels

While starting Jenkins,

  • By default, Jenkins spawns agents conservatively. Say, if there are 2 builds in queue, it won't spawn 2 executors immediately. It will spawn one executor and wait for sometime for the first executor to be freed before deciding to spawn the second executor. Jenkins makes sure every executor it spawns is utilized to the maximum.
  • If you want to override this behaviour and spawn an executor for each build in queue immediately without waiting, you can use these flags during Jenkins startup:
-Dhudson.slaves.NodeProvisioner.initialDelay=0
-Dhudson.slaves.NodeProvisioner.MARGIN=50
-Dhudson.slaves.NodeProvisioner.MARGIN0=0.85

Jenkins Kuberenetes Plugin' Github repo has good one-line description of all parameters

-- doer_uvc
Source: StackOverflow