Home DevOps Jenkins Kubernetes Deployment: Build Agents That Survive Production Chaos
Advanced ✅ Tested on Jenkins 2.440+ | Kubernetes Plugin 1.0+ | K8s 1.28+ 7 min · June 21, 2026

Jenkins Kubernetes Deployment: Build Agents That Survive Production Chaos

Deploy Jenkins on Kubernetes with production-hardened build agents.

N
Naren Founder & Principal Engineer

20+ years shipping production infrastructure and CI/CD at scale. Lessons pulled from things that broke in production.

Follow
Production
production tested
July 15, 2026
last updated
2,406
articles · all by Naren
Before you start⏱ 30 min
  • Production DevOps experience
  • Deep understanding of the tool's internals
  • Experience debugging distributed systems
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer
  • Deploy Jenkins controller as a Kubernetes Deployment with persistent volume for JENKINS_HOME.
  • Use the Kubernetes plugin to dynamically provision build agents as pods, each with its own container spec.
  • Configure agent pods with resource requests/limits, node selectors, and tolerations to avoid noisy neighbor issues.
  • Implement pod lifecycle hooks (preStop) to gracefully terminate builds during node drains.
  • Use ConfigMaps for Jenkins configuration (e.g., JCasC) to ensure reproducible deployments.
  • Enable Prometheus monitoring and set up alerts for pod failures, queue depth, and agent provisioning latency.
  • Store build artifacts in external object storage (S3, GCS) to avoid pod ephemeral storage loss.
  • Use a dedicated service account with minimal RBAC permissions for the Jenkins controller to manage pods.
✦ Definition~90s read
What is Jenkins Kubernetes Deployment?

Jenkins Kubernetes Deployment is the practice of running the Jenkins controller as a Deployment in a Kubernetes cluster, and using the Kubernetes plugin to dynamically provision build agents as ephemeral pods. The controller stores its state on a PersistentVolume (e.g., using NFS or EBS) to survive pod restarts.

Imagine Jenkins is a construction foreman.

Agents are spun up per build request, each in its own pod with a defined container image, resource limits, and environment. This architecture decouples the CI/CD workload from the underlying infrastructure, allowing elastic scaling, cost savings (pay-per-build), and improved isolation.

The Kubernetes plugin communicates with the cluster API to create agent pods, which register back to the controller via JNLP (Java Network Launch Protocol) or SSH. Production deployments require careful configuration of pod templates, service accounts, and network policies.

Plain-English First

Imagine Jenkins is a construction foreman. In a traditional setup, he has a fixed crew of workers (agents) that he sends to build houses (jobs). If a worker gets sick or a storm hits, the project stalls. Now, picture the foreman moving to a city where workers are like Uber drivers—they appear on demand, work for a specific task, and leave. The foreman (Jenkins controller) lives in a stable apartment (Kubernetes pod) with his blueprints (JENKINS_HOME) stored in a fireproof safe (persistent volume). When a new house needs building, he calls a dedicated worker pod that brings its own tools (container image). If that worker pod crashes, Kubernetes automatically spawns a new one—no more waiting for a sick worker to recover. The foreman also has a rule: if a storm is coming (node drain), he gives each worker 30 seconds to pack up (preStop hook) before the scaffolding collapses. This is Jenkins on Kubernetes—elastic, self-healing, and chaos-resistant.

⚙ Browser compatibility
Latest versions — ✓ supported
ChromeFirefoxSafariEdge

I was on call at 3 AM when the first page hit: 'Jenkins queue depth > 1000'. Our monolithic Jenkins server, running on a bare-metal box, was thrashing. Builds were timing out, agents were stuck in 'pending' state, and the ops team was manually restarting the service every two hours. The root cause? A single Java memory leak in a plugin that caused the controller to GC for 10 minutes every hour. We had no isolation—one rogue job could kill the entire CI/CD pipeline. That night, I decided to migrate our entire Jenkins infrastructure to Kubernetes. It wasn't just about containerization; it was about building a system where agent failures are expected, not exceptional. Over the next six months, we transitioned to a Kubernetes-native Jenkins setup, and the chaos became manageable. This article documents the exact patterns, commands, and incidents that shaped our production deployment.

1. Architecture Overview: Controller and Agent Separation

The foundation of a production Jenkins on Kubernetes setup is a clear separation between the controller and agents. The controller runs as a Deployment with a single replica (for simplicity) and uses a PersistentVolumeClaim for JENKINS_HOME. Agents are ephemeral pods managed by the Kubernetes plugin. The controller must have a ServiceAccount with permissions to create, list, and delete pods in the agent namespace. We use a dedicated namespace 'jenkins' for the controller and 'jenkins-agents' for agent pods to enforce RBAC boundaries. The controller exposes two ports: 8080 (HTTP) and 50000 (JNLP). The JNLP port is used for agent-controller communication and should not be exposed externally. In production, we use an internal LoadBalancer or ClusterIP service for the controller. The plugin configuration includes a Kubernetes Cloud definition with the cluster's API server URL, credentials (usually a token), and pod templates. Each pod template specifies a container image (e.g., 'jenkins/inbound-agent:latest'), resource requests/limits, and a service account for the agent. We also set 'Jenkins URL' to the internal service DNS name (e.g., 'http://jenkins-service.jenkins.svc.cluster.local:8080') so agents can reach the controller without external DNS.

📊 Production Insight
We initially used the default 'jenkins/jnlp-slave' image but switched to 'jenkins/inbound-agent' for better security and smaller footprint. Always pin the agent image version (e.g., '4.13-1') to avoid unexpected plugin changes.
🎯 Key Takeaway
Design the controller as a stateful singleton with persistent storage, and agents as stateless, ephemeral pods. Use separate namespaces and service accounts for isolation.
jenkins-kubernetes-deployment diagram 1 K8s Deployment Pipeline Code to production via Kubernetes Build & Package Maven/Gradle compile Docker Build docker.build(registry/app) Push to Registry ECR / Docker Hub / GCR kubectl set image Rolling update Kubernetes Cluster Deployment | Service | Ingress | ConfigMap Health Check Readiness probe Rollback kubectl rollout undo THECODEFORGE.IO
thecodeforge.io
Jenkins Kubernetes Deployment

2. Persistent Storage: JENKINS_HOME and Workspaces

JENKINS_HOME must survive pod restarts. We use a PersistentVolumeClaim (PVC) with ReadWriteOnce access mode, backed by an EBS volume (on AWS) or a GCE PD (on GCP). The PVC is mounted at '/var/jenkins_home' in the controller pod. For workspaces, we have two options: ephemeral (default) or persistent. Ephemeral workspaces are lost when an agent pod is deleted, which is fine for simple builds. However, for large builds that take hours, we use a shared PVC mounted on all agent pods. The PVC is created with ReadWriteMany (e.g., using NFS or EFS). In the Kubernetes plugin pod template, we add a volume mount for the workspace. We also configure Jenkins to use 'Custom Workspace' per job to point to a subdirectory on the shared volume. This avoids workspace collisions. Important: The shared volume must be fast enough to handle concurrent I/O. We learned this the hard way when NFS performance caused build times to double. We switched to a dedicated EFS with provisioned throughput.

📊 Production Insight
Always set resource requests and limits on the PVC storage class. We use 'gp3' on EKS with 3000 IOPS minimum. Monitor volume usage with Prometheus and set alerts at 80% capacity.
🎯 Key Takeaway
Use a separate PVC for workspaces with ReadWriteMany access mode. Test I/O performance under load. Implement cleanup jobs to remove old workspace directories.

3. Pod Templates: Crafting the Perfect Agent

The pod template defines the agent's container spec, including image, resource requirements, environment variables, and volumes. In production, we create multiple templates for different build types: Java (Maven), Node.js, Python, and Docker. Each template has a unique label (e.g., 'java-agent', 'node-agent') that jobs can match. We set resource requests to 500m CPU and 512Mi memory for small builds, and limits to 2 CPU and 4Gi for large builds. We also configure a 'jnlp' container that runs the agent process, and optionally a 'sidecar' container for Docker-in-Docker (DinD). For DinD, we use a privileged container with a hostPath volume for /var/run/docker.sock (careful with security). We also set environment variables like 'JENKINS_URL', 'JENKINS_SECRET', and 'JENKINS_AGENT_NAME'. The pod template can also include init containers to pre-warm the workspace or install tools. We use ConfigMaps to inject custom scripts. One gotcha: the agent pod must have a service account that can access the cluster API if the build needs to run kubectl commands.

📊 Production Insight
We had a security incident where an agent pod with Docker socket mounted allowed a malicious job to escape the container. We now use 'kaniko' instead of DinD for building images, eliminating the need for privileged containers.
🎯 Key Takeaway
Design pod templates for specific build types. Avoid privileged containers if possible. Use init containers for setup tasks. Pin image versions and scan for vulnerabilities.
jenkins-kubernetes-deployment diagram 2 K8s Agent Pod Template Dynamic Jenkins agents as K8s pods Pod Template Definition Kubernetes plugin jnlp Container Jenkins agent JAR Tools Containers Maven | JDK | Docker Sidecar Containers Database | Browser Pod Created Dynamic provisioning Build Executes Pipeline runs in pod Pod Terminated Auto cleanup THECODEFORGE.IO
thecodeforge.io
Jenkins Kubernetes Deployment

4. Resource Management: Avoiding Noisy Neighbors

Without proper resource limits, one build can starve others. We set CPU and memory requests/limits on both the controller and agent pods. For the controller, we allocate 2 CPU and 4Gi memory with limits of 4 CPU and 8Gi. For agents, we use the resource configuration in the pod template. We also set a default node selector to schedule agents on specific node pools (e.g., 'ci-cd' pool with larger instances). To prevent agents from consuming all cluster resources, we configure a maximum number of agents per cloud (e.g., 50) and a timeout for idle agents (e.g., 10 minutes). We also use pod priority classes: high priority for controller and critical agents, low priority for test agents. This ensures that when nodes are under pressure, less important builds are evicted first. We monitor resource utilization with Grafana dashboards and set up alerts when CPU usage exceeds 80% on agent nodes.

📊 Production Insight
We once had a memory leak in a build script that caused an agent pod to consume 10Gi memory, triggering OOM kills on other pods. We now enforce memory limits and use 'requests' equal to 'limits' for critical agents to prevent bursting.
🎯 Key Takeaway
Always set resource requests and limits. Use node selectors to isolate CI workloads. Implement pod priority classes. Monitor and alert on resource usage.

5. Networking: JNLP, DNS, and Security Policies

Agent pods communicate with the controller via JNLP on port 50000 (TCP). The controller's service must be reachable from agent pods. We use a ClusterIP service for the controller, and agents use the internal DNS name (e.g., 'jenkins-controller.jenkins.svc.cluster.local:50000'). Network policies are crucial: we create a policy that allows ingress from agent namespace to controller on port 50000, and egress from controller to agent pods on ephemeral ports. We also restrict egress from agent pods to only necessary external services (e.g., Docker Hub, Git repositories). For external access to the Jenkins UI, we use an Ingress with TLS termination. We use cert-manager to auto-renew certificates. One issue we faced: agent pods could not resolve DNS names due to cluster DNS misconfiguration. We added a dnsConfig to the pod template with custom nameservers. Also, ensure that the Jenkins URL in the plugin configuration matches the internal service URL, not the external ingress URL.

📊 Production Insight
We had a security audit that flagged the JNLP port as open to the internet. We immediately changed the service type from LoadBalancer to ClusterIP and added a NetworkPolicy to restrict access.
🎯 Key Takeaway
Use ClusterIP for controller service. Implement NetworkPolicies for zero-trust networking. Properly configure DNS and Jenkins URL. Use Ingress with TLS for UI access.

6. Security: RBAC, Secrets, and Pod Security

The Jenkins controller's service account needs permissions to manage pods. We create a Role in the agent namespace that allows create, get, list, watch, delete on pods, and bind it to the controller's service account via a RoleBinding. We avoid using cluster-admin. For secrets (e.g., Git credentials, Docker registry passwords), we use Jenkins credentials plugin backed by Kubernetes secrets. The controller mounts a secret volume containing the credentials.xml file (or uses the Credentials Provider plugin). Agent pods should not have access to the controller's secrets. We use PodSecurityPolicies (or OPA/Gatekeeper) to restrict agent pods: no privileged containers, read-only root filesystem, and drop all capabilities. For Docker builds, we use kaniko instead of DinD to avoid privileged mode. We also scan agent images with Trivy in a pipeline and fail builds if critical vulnerabilities are found.

📊 Production Insight
A developer accidentally committed a Jenkins API token to a public repo. We rotated all credentials and implemented a pre-commit hook to scan for secrets. Now we use HashiCorp Vault for dynamic credentials.
🎯 Key Takeaway
Follow least privilege for service accounts. Use Kubernetes secrets for Jenkins credentials. Implement PodSecurityPolicies. Regularly scan images and rotate secrets.

7. Configuration as Code: Reproducible Jenkins

Using Jenkins Configuration as Code (JCasC) plugin, we define the entire Jenkins configuration in a YAML file stored in Git. This includes system settings, security realms, authorization strategies, and cloud configurations (Kubernetes plugin). We mount the JCasC YAML as a ConfigMap in the controller pod. On startup, Jenkins applies the configuration. This ensures that every controller pod is identical and can be recreated from scratch. We also version the ConfigMap and use a checksum annotation to trigger a rolling update when the config changes. For plugin management, we use the plugin-installation-manager-tool in the Dockerfile to pre-install a list of plugins. We pin plugin versions to avoid incompatibilities. One challenge: some plugins require restart after installation, which we handle by setting the 'restart' option in JCasC.

📊 Production Insight
We had a configuration drift when an admin manually changed settings via the UI. We now enforce that all changes go through Git and use a pre-commit hook to validate the JCasC YAML against the Jenkins schema.
🎯 Key Takeaway
Use JCasC for all configurations. Store config in Git. Use ConfigMaps to inject config. Automate plugin installation. Validate changes with a CI pipeline.

8. Monitoring and Alerting: Observability for CI/CD

We deploy the Prometheus plugin on Jenkins and expose metrics at /prometheus. Key metrics: queue length, executor count, build duration, and job status. We also monitor agent pod lifecycle with kube-state-metrics and cAdvisor. We set up alerts in Prometheus: if queue depth > 100 for 5 minutes, alert; if agent provisioning latency > 2 minutes, alert; if controller JVM heap > 80%, alert. We use Grafana dashboards to visualize build trends and resource usage. For logs, we use Fluentd to send Jenkins logs to Elasticsearch. We also monitor the Kubernetes cluster itself: node CPU/memory, pod restarts, and persistent volume usage. One incident: a silent build failure due to a plugin bug was not caught because we only monitored build status, not build log errors. We now parse build logs for error patterns and alert on them.

📊 Production Insight
We missed a critical alert because the Prometheus plugin was not scraping the controller due to a network policy change. We now have a synthetic check that pings the /prometheus endpoint every minute.
🎯 Key Takeaway
Monitor Jenkins metrics, agent pods, and cluster health. Set up alerts for key indicators. Parse build logs for errors. Use synthetic checks to verify monitoring itself.

9. Graceful Shutdowns: Surviving Node Drains and Rollouts

When a Kubernetes node is drained or a rollout update occurs, agent pods receive a SIGTERM signal. Without handling, builds are killed instantly. We add a preStop lifecycle hook to the agent container that runs a script to disconnect from Jenkins gracefully. The script sends a 'shutdown' command to the agent process (via jenkins-cli.jar or the agent's shutdown API). We also set a terminationGracePeriodSeconds of 60 seconds to allow builds to complete. For the controller, we handle SIGTERM by running a script that stops accepting new builds and waits for running builds to finish. This is configured in the Jenkins init script. We also use a readiness probe on the controller to take it out of service when shutting down. In production, we use a preStop hook that calls 'curl -X POST http://localhost:8080/exit' (with authentication) to shut down Jenkins cleanly.

📊 Production Insight
During a cluster upgrade, the controller was killed before the preStop hook completed because the grace period was too short. We increased terminationGracePeriodSeconds to 120 seconds and added a sleep in the hook to wait for builds.
🎯 Key Takeaway
Implement preStop hooks for both controller and agents. Set adequate termination grace periods. Use readiness probes to remove pods from service before shutdown. Test with chaos engineering.

10. Scaling: Handling Burst Builds and Cost Optimization

During peak hours (e.g., after a code freeze), the number of builds can spike 10x. The Kubernetes plugin automatically provisions new agent pods, but we must ensure the cluster can handle the load. We use cluster autoscaler to add nodes when pods are pending. We configure the autoscaler with a minimum and maximum node count, and use spot instances for cost savings (with a fallback to on-demand). For agent pods, we set a node affinity to prefer spot instances. We also use pod disruption budgets to prevent all agents from being evicted at once. To control costs, we set a maximum number of concurrent agents (e.g., 100) and use a queue-based throttle. We also implement a 'quiet hours' policy where non-critical builds are postponed during off-peak hours. We use a custom script that checks the time and delays builds with a low priority label.

📊 Production Insight
We had a billing shock when a malicious job triggered thousands of parallel builds, spawning 500 agent pods and scaling the cluster to 50 nodes. We now enforce a per-user concurrency limit and use a webhook to validate job parameters.
🎯 Key Takeaway
Use cluster autoscaler with spot instances. Set hard limits on concurrent agents. Implement cost controls and budget alerts. Validate job triggers to prevent abuse.

11. Backup and Disaster Recovery: What If Everything Goes Down?

We back up JENKINS_HOME every hour using a CronJob that creates a snapshot of the PVC. We also back up the JCasC ConfigMap and plugin list. The backup is stored in an S3 bucket with versioning. For disaster recovery, we have a script that deploys a new Jenkins controller from scratch: it creates a new PVC from the latest snapshot, applies the ConfigMap, and starts the deployment. The recovery time is under 30 minutes. We test the recovery process quarterly. One issue: the backup script failed silently because the PVC was not mounted read-only during backup. We now use a sidecar container that mounts the PVC read-only and performs the backup. We also back up the Jenkins secrets (credentials.xml) encrypted with KMS. For agent pods, we don't back up anything since they are ephemeral.

📊 Production Insight
We had a cluster failure that deleted all PVCs. The backup was stored on a different cluster's S3 bucket, so we were able to restore. We now replicate backups to a different region.
🎯 Key Takeaway
Back up JENKINS_HOME and configuration regularly. Store backups off-cluster. Test recovery procedures. Use encrypted backups for secrets. Document the recovery process step-by-step.
jenkins-kubernetes-deployment diagram 3 Rolling vs Blue-Green vs Canary Kubernetes deployment strategies Rolling Update Gradual pod replacement No downtime Blue-Green Full new stack Instant switch Canary % traffic shift Gradual rollout strategy: { type: RollingUpdate | Recreate } Deployment spec maxSurge: 25% Extra pods during update maxUnavailable: 25% Pods down during update THECODEFORGE.IO
thecodeforge.io
Jenkins Kubernetes Deployment

12. Advanced Patterns: Multi-Cluster, Hybrid, and GitOps

For large organizations, a single Jenkins instance may not suffice. We run multiple Jenkins controllers in different clusters (e.g., one per region) and use a load balancer to distribute jobs. The Kubernetes plugin can be configured to provision agents from multiple clusters via the 'Kubernetes Cloud' configuration. We also use a hybrid approach: on-premises agents for sensitive builds (e.g., PCI compliance) and cloud agents for standard builds. For GitOps, we use Argo CD to manage the Jenkins deployment itself. The Jenkins configuration (JCasC) and plugin list are stored in a Git repository, and Argo CD syncs the cluster state to the repo. This enables automated rollbacks and audit trails. We also implement a self-service model where teams can create their own pod templates via a custom resource (CRD) that generates the JCasC configuration.

📊 Production Insight
We had a misconfiguration in the multi-cluster setup where agents from one cluster tried to connect to the wrong controller. We solved this by using distinct labels and a unique 'Jenkins URL' per cloud definition.
🎯 Key Takeaway
Consider multi-cluster and hybrid deployments for scale and compliance. Use GitOps to manage Jenkins configuration. Implement self-service for teams with CRDs. Ensure unique identifiers per cloud.
● Production incidentPOST-MORTEMseverity: high

The Great Agent Disappearance: When Node Drains Killed Every Build

Symptom
During a node drain, all agent pods were evicted without completing builds. Build logs ended abruptly with 'Connection refused' errors. The queue grew to 500+ pending jobs.
Assumption
We assumed Kubernetes would gracefully terminate pods, allowing Jenkins to reconnect after rescheduling. We had not configured any termination handling.
Root cause
Agent pods had no preStop hook or grace period. When the node was drained, pods received SIGTERM and were killed immediately. Jenkins agents had no chance to disconnect cleanly or transfer workspace state.
Fix
Added a preStop lifecycle hook to agent pods that sends a 'shutdown' command to the Jenkins agent process, with a 30-second timeout. Also configured the Kubernetes plugin to use a persistent workspace volume (PVC) so that even if the pod is killed, the workspace data survives.
Key lesson
  • Always test node drain scenarios in a staging environment.
  • Implement graceful shutdown for all stateful pods.
  • Use persistent volumes for workspaces to avoid data loss.
Production debug guideReal-world failure modes and how to fix them fast5 entries
Symptom · 01
Pod stuck in CrashLoopBackOff after plugin upgrade
Fix
Check Jenkins logs: kubectl logs <pod-name> -c jenkins. If plugin incompatibility, rollback by redeploying with previous image tag. For persistent fix, pin plugin versions in your Dockerfile or use a plugin management tool like jenkins-plugin-cli with explicit versions.
Symptom · 02
Builds fail with 'No space left on device' on ephemeral pods
Fix
Increase the ephemeral storage request/limit in the pod template. Set ephemeral-storage in resources. Also configure Jenkins to clean workspace after each build: Jenkins > Manage Jenkins > Configure System > Workspace Cleanup Plugin.
Symptom · 03
Jenkins master becomes unresponsive under high load
Fix
Check resource usage: kubectl top pod <master-pod>. If CPU/memory limits are hit, increase them. Also tune Jenkins JVM heap: set -Xmx in JAVA_OPTS environment variable. Consider adding horizontal pod autoscaling based on custom metrics like queue length.
Symptom · 04
Agent pods fail to connect to master
Fix
Verify network policies allow traffic on port 50000 (or custom JNLP port). Check agent pod logs: kubectl logs <agent-pod>. Common causes: wrong Jenkins URL, missing secret, or TLS mismatch. Ensure JENKINS_URL env var is set correctly and the secret matches the agent configuration.
Symptom · 05
Persistent volume claim (PVC) remains in Pending state
Fix
Check PVC events: kubectl describe pvc <pvc-name>. Common issues: storage class not found, insufficient capacity, or node affinity. Verify storage class exists and has a provisioner. If using local volumes, ensure node labels match.
★ Jenkins on K8s: Quick Debug Cheat SheetImmediate actions for the most common production issues.
Pod CrashLoopBackOff
Immediate action
Check logs and resource limits
Commands
kubectl logs <pod> -c jenkins --tail=50
Fix now
Increase memory limit or rollback plugin version
Build stuck in queue+
Immediate action
Check agent availability and labels
Commands
kubectl get pods -l jenkins=agent
Fix now
Scale up agent count or adjust label matching
Agent connection timeout+
Immediate action
Verify network and secret
Commands
kubectl exec <master-pod> -- curl -s http://localhost:8080/computer/api/json
Fix now
Restart agent pod or regenerate secret
PVC stuck Pending+
Immediate action
Check storage class and capacity
Commands
kubectl describe pvc <pvc-name>
Fix now
Create correct storage class or expand capacity
Out of memory (OOMKilled)+
Immediate action
Increase memory limits
Commands
kubectl describe pod <pod> | grep -A2 Limits
Fix now
Edit deployment: kubectl edit deployment <name> and increase memory
Jenkins Kubernetes Deployment: Feature Comparison
featuretraditional_jenkinskubernetes_jenkinsproduction_benefit
Agent ProvisioningStatic agents (VMs or bare metal) managed manuallyDynamic pods created on demand via Kubernetes pluginElastic scaling, no idle capacity, cost savings
IsolationAll builds share the same agent workspaceEach build gets a dedicated pod with isolated filesystemNo interference between builds, improved security
Resource ManagementFixed resources per agent, often overprovisionedResource requests/limits per pod, fine-grained controlBetter utilization, avoid noisy neighbors
Disaster RecoveryFull VM backup, slow restore (hours)PVC snapshots + JCasC, restore in minutesFaster recovery, infrastructure as code
ScalabilityLimited by number of static agentsHundreds of agents, cluster autoscalerHandle burst loads, pay-per-use
SecurityAgents often have broad access to networkNetworkPolicies, PodSecurityPolicies, least privilegeGranular security controls, reduced attack surface
📦 Downloadable Quick Reference

Print-friendly master reference covering all topics in this track.

⇩ Download PDF

Key takeaways

1
Separate controller and agents into different namespaces with dedicated service accounts.
2
Use PVCs for JENKINS_HOME and shared workspaces; back them up regularly.
3
Design pod templates with resource requests/limits, node selectors, and tolerations.
4
Implement preStop hooks for graceful shutdown of both controller and agents.
5
Use JCasC for reproducible configuration and store it in Git.
6
Monitor Jenkins metrics, agent pods, and cluster health with Prometheus and Grafana.
7
Enforce network policies and pod security policies to minimize attack surface.
8
Test disaster recovery procedures quarterly and automate backups.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
How does the Kubernetes plugin provision agent pods? Describe the lifecy...
Q02SENIOR
What is the purpose of the JNLP port? How do you secure it in a producti...
Q03SENIOR
How would you handle a scenario where agent pods are stuck in 'Pending' ...
Q04SENIOR
Explain how you would implement graceful shutdown for Jenkins controller...
Q05SENIOR
What are the trade-offs between using ephemeral vs. persistent workspace...
Q06JUNIOR
How do you manage Jenkins configuration as code? Describe the tools and ...
Q07SENIOR
Describe a production incident you encountered with Jenkins on Kubernete...
Q08SENIOR
How would you scale Jenkins to handle 1000+ concurrent builds across mul...
Q01 of 08SENIOR

How does the Kubernetes plugin provision agent pods? Describe the lifecycle from job trigger to pod creation.

ANSWER
The Kubernetes plugin uses a custom controller that watches the Jenkins job queue. When a job requires a label matching an agent template, the plugin creates a Pod object via the Kubernetes API, using the configured container templates and pod template. The pod goes through Pending, Running phases, and once the Jenkins agent JAR inside the container connects back to the master, the job executes. After completion, the plugin terminates the pod based on the idle timeout or immediately if configured.
FAQ · 8 QUESTIONS

Frequently Asked Questions

01
What is the difference between a Jenkins agent and a Kubernetes pod?
02
How do I configure the Jenkins URL for agents?
03
Can I use the same agent pod for multiple builds?
04
How do I debug a failing agent connection?
05
What are the best practices for storing Jenkins credentials?
06
How do I handle Docker builds without privileged containers?
07
What is the recommended way to upgrade Jenkins plugins?
08
How do I ensure high availability for the Jenkins controller?
N
Naren Founder & Principal Engineer

20+ years shipping production infrastructure and CI/CD at scale. Lessons pulled from things that broke in production.

Follow
Verified
production tested
July 15, 2026
last updated
2,406
articles · all by Naren
🔥

That's Jenkins. Mark it forged?

7 min read · try the examples if you haven't

Previous
Jenkins Docker Integration
20 / 41 · Jenkins
Next
Jenkins SonarQube Quality Gates