How do you configure dynamic Kubernetes agents in Jenkins for production use?
IntermediateProductionJenkins in Production
Answer
Define the cloud in JCasC with the controller's internal URL, a namespace for agents, and the WebSocket or JNLP port. Create pod templates with resource requests/limits (builds without limits starve nodes), a service account with minimal RBAC, node selectors/tolerations for build node pools (spot instances), and idleMinutes or activeDeadlineSeconds to prevent stuck pods. Use caching via persistent volumes or a remote cache, not pod-local state.
jenkins:
clouds:
- kubernetes:
name: k8s
namespace: jenkins-agents
jenkinsUrl: http://jenkins.jenkins.svc:8080
webSocket: true
templates:
- name: maven
label: maven
containers:
- name: maven
image: maven:3.9-eclipse-temurin-21
command: sleep
args: infinity
resourceRequestCpu: "1"
resourceLimitMemory: 3Gi
More on Jenkins in Production
How do you run Jenkins for high availability and scale?AdvancedHow do you tune the Jenkins controller JVM and avoid out-of-memory crashes?AdvancedHow do you back up and restore Jenkins?IntermediateHow do you upgrade Jenkins and its plugins safely?IntermediateHow do you harden a Jenkins controller?AdvancedWhat are the pitfalls of Docker socket mounting in Jenkins agents, and what are alternatives?Advanced