Here is my containerTemplate
snippet from Jenkinsfile which creates a pod and a container called mvn-c1 onto Kubernetes.
containerTemplate(
name: 'mvn-c1',
image: 'mycompany.lab/build_images/mvn_c1_k8s:0.3',
privileged: true,
ttyEnabled: true,
command: 'cat',
imagePullSecrets: ['docker-repo'],
volumeMounts: [ name: 'maven-repo1' , mountPath: '/root/.m2' ],
volumes: [
nfsVolume( mountPath: '/root/.m2', serverAddress: 'nfs-server-ip',
serverPath: '/jenkins_data', readOnly: false ),
]
)
The problem is that the volume is not able to mount to the container nor doesn't show any parse errors on the console.
I have referred this documentation to construct the containerTemplate
Has anybody had luck trying this method?
Firstly thanks for the detailed explanation about the endpoint correlation of NFS IP with namepsaces.. and my apologies for the long gap between the posts.
I have Intentionally hidden podTemplate and posted Jenkinsfile snippet.
I was able to achieve this with the desired result by giving reference on my slave POD yaml file which has the NFS ip and mount point tags.
I referred it as below:
kubernetes {
label "slavepod-${UUID.randomUUID().toString()}"
yamlFile './k8s-pod.yaml'
}
}
and my POD yaml has the following
volumes:
- name: maven-repo1
nfs:
server: NFS-IP
path: /jenkins_data
Welcome on StackOverflow @Vamshi
I think you have two issues with your current Pipeline definition:
volumes
are part of podTemplate not containerTemplateWARNING: Unknown parameter(s) found for class type 'org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate': volumes
Here is a fully working example:
podTemplate(containers: [
containerTemplate(name: 'maven',
image: 'maven:3.3.9-jdk-8-alpine',
ttyEnabled: true,
command: 'cat')
],
volumes: [
nfsVolume( mountPath: '/root/.m2', serverAddress: '10.0.174.57',
serverPath: '/', readOnly: false ),
]
) {
node(POD_LABEL) {
stage('Get a Maven project') {
container('maven') {
stage('Build a Maven project') {
sh 'while true; do date > /root/.m2/index.html; hostname >> /root/.m2/index.html; sleep $(($RANDOM % 5 + 5)); done'
}
}
}
}
}
Verifying the correctness of nfs-based Persistence Volume mounted inside POD:
kubectl exec container-template-with-nfs-pv-10-cl42l-042tq-z3n7b -c maven -- cat /root/.m2/index.html
Output: Mon Aug 26 14:47:28 UTC 2019 nfs-busybox-9t7wx