Jenkins Kubernetes plugin agent spawning¶
The Jenkins Kubernetes plugin enables a Jenkins controller to dynamically spawn agents as Kubernetes Pods.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] This setup is commonly deployed using the official Jenkins Helm chart, which installs a Jenkins server configured to utilize this plugin for build automation.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Functionality¶
When configured, the plugin treats the Kubernetes cluster as a "cloud" resource.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] Instead of maintaining a static pool of agent machines, Jenkins on-demand creates ephemeral Pods to execute build pipelines.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] Once the build task is complete, these agent pods are terminated, allowing resources to be freed up for other operations.
Kubernetes API Configuration¶
The plugin requires communication with the Kubernetes API to manage the lifecycle of agent pods.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] Within the Helm chart configuration, the agent.maxRequestsPerHostStr setting controls the maximum concurrent connections allowed to the Kubernetes API.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] The default value is often 32, but this can be adjusted to handle high volumes of agent spawning operations or to comply with API server rate limits.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Pod Templates¶
Agent pods are defined using Pod Templates, which specify the container images, labels, and resource requirements for the agents.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] These templates can be configured directly within the Helm chart values.
Custom Pod Templates¶
Users can define custom Pod templates under the agent.podTemplates key in the configuration.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] Each key in this section acts as a label for a specific Pod template configuration.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] For the templates to be loaded correctly, the controller.JCasC.defaultConfig value must be set to true.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
The Kubernetes plugin automatically injects the default JNLP (Java Network Launch Protocol) agent container into the Pod; therefore, it is not necessary to manually define the JNLP container within custom Pod templates.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Example configuration for a Python agent:
agent:
podTemplates:
python: |
- name: python
label: jenkins-python
serviceAccount: jenkins
containers:
- name: python
image: python:3
command: "/bin/sh -c"
args: "cat"
ttyEnabled: true
Additional Agents¶
The additionalAgents configuration block allows for the definition of multiple Pod templates that inherit values from a base agent configuration.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] This is useful for defining variations of agents (e.g., different tools or images) without repeating the entire configuration.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] Properties such as podName, customJenkinsLabels, and container images can be overridden for each specific additional agent.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Volume Mounting¶
Agents often require access to secrets, configurations, or shared storage. The Helm chart supports injecting various Kubernetes Volume types into agent pods, including ConfigMap, EmptyDir, HostPath, Nfs, PVC, and Secret.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] This is configured via the agent.volumes parameter in values, allowing the user to specify the volume type, the name of the secret/ConfigMap, and the mountPath inside the Pod.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Example of mounting a secret:
agent:
volumes:
- type: Secret
secretName: jenkins-mysecrets
mountPath: /var/run/secrets/jenkins-mysecrets
Sources¶
^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Related¶
- Jenkins
- Kubernetes
- Helm
- [[Continuous Integration]]