Kubernetes Pod templates¶
In the context of Jenkins integration with Kubernetes, pod templates are definitions used to specify the configuration of agent pods that are spawned dynamically to run build jobs.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
These templates are configured within the Jenkins Kubernetes plugin, allowing Jenkins to communicate with the Kubernetes API to manage build agent lifecycle.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Configuration Methods¶
Pod templates can be configured using two primary methods within the Helm chart: agent.podTemplates and additionalAgents.
Using agent.podTemplates¶
This method allows for the explicit addition of custom Pod templates to the default configured Kubernetes cloud.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
To use this method, you must ensure that controller.JCasC.defaultConfig is set to true.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Configuration involves adding keys under agent.podTemplates, where each key acts as a label for the template.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] The JNLP container is automatically injected by the Kubernetes plugin, so it does not need to be defined manually in the template.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Example Configuration:
agent:
podTemplates:
python: |
- name: python
label: jenkins-python
serviceAccount: jenkins
containers:
- name: python
image: python:3
command: "/bin/sh -c"
args: "cat"
ttyEnabled: true
resourceRequestCpu: "400m"
resourceRequestMemory: "512Mi"
Using additionalAgents¶
The additionalAgents value provides a simplified way to configure multiple Pod templates.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md] Each agent defined under this section corresponds to an agent configuration and inherits default values from the main agent block, requiring only values that differ to be specified.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
This method is useful for defining distinct agent types (e.g., Maven, Python) without rewriting the entire configuration for each.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Example Configuration:
additionalAgents:
[Maven](<./maven.md>):
podName: [Maven](<./maven.md>)
customJenkinsLabels: [Maven](<./maven.md>)
image: jenkins/jnlp-agent-maven
tag: latest
python:
podName: python
customJenkinsLabels: python
sideContainerName: python
image: python
tag: "3"
Volume Mounting¶
Pod templates support the injection of Kubernetes volumes into agent pods, allowing build agents to access secrets, configurations, or other data.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
This is configured using the agent.volumes parameter, supporting types such as ConfigMap, Secret, PVC, and EmptyDir.^[400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md]
Example:
agent:
volumes:
- type: Secret
secretName: jenkins-mysecrets
mountPath: /var/run/secrets/jenkins-mysecrets
Related Concepts¶
- Jenkins
- Helm
- Kubernetes
- [[Jenkins Configuration as Code]]
Sources¶
- 400-devops__06-Kubernetes__devops-helm__helm-jenkins__README.md