Deploying Jenkins on Kubernetes for CI/CD with Static and Dynamic Agents
This guide walks through installing Jenkins on a Kubernetes cluster using manual YAML manifests, configuring persistent storage, service accounts, ingress, and then demonstrates both static and dynamic Jenkins agents, including pipeline setup, plugin installation, and CI/CD workflow execution.
This article explains how to set up a Jenkins CI/CD platform on a Kubernetes cluster using the familiar Jenkins tool, covering installation, configuration, and usage of both static and dynamic agents.
Installation : The Jenkins server is deployed as a set of Kubernetes resources defined in jenkins.yaml , which includes a PersistentVolume, PersistentVolumeClaim, ServiceAccount, ClusterRole, ClusterRoleBinding, Deployment, Service, and Ingress. The deployment uses the official jenkins/jenkins:lts-jdk11 Docker image, sets the JAVA_OPTS=-Dhudson.model.DownloadService.noSignatureCheck=true environment variable to bypass update‑center signature checks, and mounts /var/jenkins_home for data persistence via a local PV.
# jenkins.yaml (excerpt)
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-local
labels:
app: jenkins
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
storageClassName: local-storage
local:
path: /data/k8s/jenkins
persistentVolumeReclaimPolicy: Retain
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node2
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc
namespace: kube-ops
spec:
storageClassName: local-storage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
# (additional resources omitted for brevity)After applying the manifest with kubectl apply -f jenkins.yaml , the Jenkins pod becomes ready, and the initial admin password can be retrieved via kubectl exec -it jenkins-pod -n kube-ops -- cat /var/jenkins_home/secrets/initialAdminPassword . The UI is accessed through the configured Ingress domain jenkins.k8s.local (with appropriate DNS or /etc/hosts mapping).
Post‑installation steps : Install the "Localization: Chinese" plugin for a Chinese UI, set a new admin password, and add essential plugins such as "Pipeline" to enable scripted pipelines.
Static agents : Create a Jenkins node via the UI, obtain its secret and URL, and apply a jenkins-agent.yaml Deployment that runs the jenkins/inbound-agent image with the required environment variables ( JENKINS_URL , JENKINS_SECRET , JENKINS_AGENT_NAME , JENKINS_AGENT_WORKDIR ). After deployment, the static agent appears in the Jenkins node list and can execute jobs.
# jenkins-agent.yaml (excerpt)
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-agent
namespace: kube-ops
spec:
selector:
matchLabels:
app: jenkins-agent
template:
metadata:
labels:
app: jenkins-agent
spec:
containers:
- name: agent
image: jenkins/inbound-agent
env:
- name: JENKINS_URL
value: http://jenkins.k8s.local
- name: JENKINS_SECRET
value:
secret-from-node
- name: JENKINS_AGENT_NAME
value: agent1
- name: JENKINS_AGENT_WORKDIR
value: /home/jenkins/workspaceDynamic agents : Install the Kubernetes plugin in Jenkins, configure a new cloud of type "Kubernetes" pointing to https://kubernetes.default.svc.cluster.local and namespace kube-ops . After testing the connection, Jenkins can launch temporary agent pods on demand. Example pipeline syntax:
pipeline {
agent {
kubernetes {
label "test01"
cloud 'Kubernetes'
yaml '''
---
kind: Pod
apiVersion: v1
metadata:
labels:
k8s-app: jenkins-agent
name: jenkins-agent
namespace: kube-ops
spec:
containers:
- name: jenkinsagent
image: jenkins/inbound-agent
imagePullPolicy: IfNotPresent
''' }
}
stages {
stage("Hello") {
steps {
script { echo "Hello Slave Pod on Kubernetes!" }
}
}
}
}When the pipeline is triggered, Jenkins creates a temporary pod (e.g., test01-jnzmb-ht0n7 ), runs the job, and automatically deletes the pod after completion, demonstrating efficient resource usage.
Overall, the guide showcases how Kubernetes provides high availability, dynamic scaling, and easy extensibility for Jenkins‑based CI/CD pipelines, turning traditional master‑slave setups into resilient, container‑native workflows.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.