How does the Jenkins Kubernetes plugin provision agents?
AdvancedConceptJenkins
Answer
When a build needs an agent matching a pod template, the plugin calls the Kubernetes API to create a pod. The pod contains a jnlp container (the inbound agent that connects back to the controller) plus any extra containers you define (maven, docker/kaniko, kubectl). Steps run in a chosen container using container('name') { ... }, sharing the workspace volume. When the build finishes, the pod is deleted.
agent {
kubernetes {
yaml '''
spec:
containers:
- name: maven
image: maven:3.9-eclipse-temurin-21
command: [sleep]
args: [infinity]
'''
}
}
// steps { container('maven') { sh 'mvn -B verify' } }
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate