Hello everyone.
At my company we have been using Jenkins for our CI infrastructure and recently we decided to start using k8s in order to provisions agents there.
So i have installed the kubernetes-plugin configured the access to our autopilot k8s cluster and created a pipeline job that builds a maven based project.
I am pasting the pipeline script below:
podTemplate(cloud: 'autopilot',
yaml: '''
apiVersion: v1
kind: Pod
metadata:
labels:
type: maven
spec:
volumes:
- name: deps
persistentVolumeClaim:
claimName: maven-repo
serviceAccount: jenkins-admin
containers:
- name: maven
image: maven:3.8.1-jdk-8
command:
- sleep
args:
- 99d
tty: true
resources:
limits:
cpu: 2000m
memory: 4096Mi
requests:
cpu: 100m
memory: 512Mi
volumeMounts:
- name: deps
mountPath: /root/.m2/repository
''') {
timestamps {
node(POD_LABEL) {
stage('Build a Maven project') {
sh "env"
checkout(scm: [$class: 'GitSCM',
branches: [[name: "master"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanBeforeCheckout']],
submoduleCfg: [],
userRemoteConfigs: [
[credentialsId: 'git-checkout-cred', name: 'origin', url: '
g...@github.com<my-git-repo>.git']]
]
)
container('maven') {
sh "ls -la"
sh "pwd"
sh(script: 'mvn clean package -DskipTests')
}
}
}
}
}
Note the i have pre-created the maven-repo pvc before invoking the pipeline.
The pipeline runs fine, it downloads the dependencies and build the project but the time it takes is high in proportion to the tasks it is executing.
For instance it the build itself takes a less than a minute (dependencies are cached) but the provisioning of the pod takes almost 3 minutes.
I am attaching some images that demonstrate the above statements
I am also attaching a build log.
What can i do in order to speedup the provisioning of the pods?
PS Jenkins control plane is on a VM outside of K8s.