How I Deployed Jenkins on Kubernetes Using Dynamic Agent Pods

In this article, I’ll walk you through how I deployed Jenkins on Kubernetes, configured dynamic agent pods, and successfully executed a pipeline using Kubernetes-native Jenkins agents.
This setup reflects real-world CI/CD architecture where Jenkins scales automatically using Kubernetes pods instead of static agents.
Why Jenkins on Kubernetes?
Traditional Jenkins agents are:
Hard to scale
Costly when idle
Difficult to manage
With Kubernetes:
Agent pods are created on demand
Pods terminate automatically after job completion
Better resource utilization
Cloud-native CI/CD
Architecture Overview
Jenkins Master runs as a Kubernetes pod
Kubernetes Plugin provisions agent pods dynamically
NodePort Service exposes Jenkins UI
ServiceAccount + RBAC allows Jenkins to manage pods
Step 1: Deploy Jenkins Master on Kubernetes
I deployed Jenkins using a Deployment manifest with:
jenkins/jenkins:lts-jdk17imageExposed ports
8080(UI) and50000(JNLP agents)emptyDirvolume for Jenkins home
This ensured Jenkins runs reliably inside the cluster.
Step 2: Expose Jenkins Using NodePort
To access Jenkins from the browser, I created a NodePort service:
Jenkins UI →
NodeIP:30000Agent communication →
50000
This made Jenkins accessible externally while keeping things simple for demo purposes.
Step 3: ServiceAccount and RBAC Configuration
Since Jenkins needs to:
Create pods
Delete pods
Watch Kubernetes resources
I created:
A ServiceAccount
A ClusterRoleBinding with
cluster-adminpermissions (for learning/demo)In production, permissions should always follow the least privilege principle.
Step 4: Configure Kubernetes Cloud in Jenkins
Inside Jenkins UI:
Manage Jenkins → Configure System → Clouds → Kubernetes
Configured:
Kubernetes URL:
https://kubernetes.default:443Jenkins URL:
http://jenkins:8080Jenkins Tunnel:
jenkins:50000Credentials: Kubernetes Service Account
Namespace:
default
This allows Jenkins to talk directly to the Kubernetes API.
Step 5: Create Jenkins Agent Pod Template
Configured an agent pod template with:
Label:
jenkins-agentImage:
jenkins/inbound-agent:lts-jdk17Container name:
jnlpWorking directory:
/home/jenkins/agent
This template is used whenever a pipeline requests an agent with this label.
Step 6: Run a Pipeline Using Kubernetes Agent
Sample pipeline:
pipeline {
agent { label ‘jenkins-agent’ }
stages {
stage(‘Test’) {
steps {
sh ‘echo Hello from Kubernetes Jenkins Agent’
}
}
}
}
What happens internally?
Jenkins requests an agent
Kubernetes creates a new pod
Pipeline runs inside the pod
Pod terminates after completion
Final Outcome
Jenkins master running on Kubernetes
Agent pods created dynamically
Pipeline executed successfully
Pods cleaned up automatically
Jenkins UI accessible via NodePort
Key Takeaways
Kubernetes-based Jenkins is scalable and efficient
No idle agents wasting resources
Best approach for cloud-native CI/CD
Strongly recommended for DevOps engineers
Who Should Read This?
DevOps Engineers
Kubernetes Beginners
CI/CD Learners
Jenkins Interview Preparation
Conclusion
Running Jenkins on Kubernetes with dynamic agent pods is a modern DevOps best practice. This setup not only improves scalability but also simplifies agent management dramatically.
If you’re preparing for DevOps interviews or real-world CI/CD projects, this architecture is a must-know.



