Running Cloud-Native Jenkins on Kubernetes
Deploy a resilient Jenkins automation controller on Kubernetes with persistent volume storage, RBAC service accounts, and dynamic ephemeral build agent pods.
Mohan Kumar BN
Senior Platform Engineer & CNCF Certified Kubestronaut
Why Run Jenkins on Kubernetes?
Running Jenkins natively on Kubernetes eliminates idle static build VMs. The Jenkins controller runs as a stateful workload backed by a PersistentVolumeClaim, while every pipeline execution dynamically provisions ephemeral Kubernetes agent pods that terminate immediately after the build completes.
Step-by-Step Deployment
1. Create Dedicated Namespace, ServiceAccount & RBAC
apiVersion: v1
kind: Namespace
metadata:
name: devops-tools
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins-admin
namespace: devops-tools
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: jenkins-admin-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: jenkins-admin
namespace: devops-tools
2. Deploy the Jenkins Controller with Persistent Storage
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: devops-tools
spec:
replicas: 1
selector:
matchLabels:
app: jenkins-server
template:
metadata:
labels:
app: jenkins-server
spec:
securityContext:
fsGroup: 1000
runAsUser: 1000
serviceAccountName: jenkins-admin
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- name: httpport
containerPort: 8080
- name: jnlpport
containerPort: 50000
volumeMounts:
- name: jenkins-data
mountPath: /var/jenkins_home
volumes:
- name: jenkins-data
persistentVolumeClaim:
claimName: jenkins-pv-claim
Configure the Kubernetes plugin inside Jenkins pointing to https://kubernetes.default.svc.cluster.local to spawn dynamic Maven and Python build pods on demand.
Related Engineering Blueprints
Deploy Self-Hosted Enterprise GitLab on Ubuntu with Ansible
Automate the deployment, TLS configuration, and day-2 tuning of a self-hosted GitLab instance on Ubuntu servers using idempotent Ansible playbooks.
Install an External Ceph Distributed Storage Cluster Using Ansible
Provision a self-healing, multi-node Ceph distributed storage cluster with Ansible to deliver replicated block (RBD), shared file (CephFS), and object storage for Kubernetes.
How to Setup High-Availability Load Balancing with HAProxy & Keepalived
Configure redundant Active/Passive HAProxy load balancers with Keepalived VRRP floating Virtual IPs (VIP) on Ubuntu 24.04 to eliminate single points of failure.