I am configuring Jenkins on Kubernetes system. It works fine to build. But in order to deploy, we need to call kubectl or helm. Currently, I am using
- lachlanevenson/k8s-kubectl:v1.8.8
- lachlanevenson/k8s-helm:latest
It is fail and throw exception: "Error from server (Forbidden): pods is forbidden: User "system:serviceaccount:jenkins:default" cannot list pods in the namespace "jenkins""
The jenkins script is simple:
def label = "worker-${UUID.randomUUID().toString()}"
podTemplate(label: label,containers: [
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]){
node(label) {
stage('Run kubectl') {
container('kubectl') {
sh "kubectl get pods"
}
}
}
}
Could you please let me know what is wrong?
Thanks,