Interview Prep/CI/CD/Jenkins in Production

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
All CI/CD questions

More on Jenkins in Production