Kubernetes jenkins pod template creating pod in wrong namespace

1.3k Views Asked by At

We have a jenkins master-slave architecture and using the Kubernetes Jenkins plugin. The podTemplate looks as below

podTemplate(label: 'builder-pod', cloud: 'kubernetes', containers: [
        containerTemplate(
                name: 'jnlp',
                image: "${artifact_repo}/jenkins-slave",
                ttyEnabled: true,
                privileged: false,
                alwaysPullImage: false,
                workingDir: '/var/jenkins_home',
                resourceRequestCpu: '1000m',
                resourceRequestMemory: '1Gi',
                resourceLimitMemory: '1.1Gi',
        )
], volumes: [hostPathVolume(mountPath: '/var/run', hostPath: '/var/run')], namespace: 'jenkins') { //podtemplate
    node('builder-pod') {
        container('jnlp') {


For whatever reason the builder-pod is being created in default namespace instead of the jenkins namespace

Any idea what could be wrong? Thanks in advance.

3

There are 3 best solutions below

1
Orlando G. On

check the name with:

kubectl config get-contexts

And then change the context namespace before deploying your pod

kubectl config <NAME> set-context --namespace=jenkins
0
pypalms On

You could always force the namespace by including that in your container definition:

containerTemplate(
                name: 'jnlp',
                namespace: 'jenkins',
                image: "${artifact_repo}/jenkins-slave",
                ttyEnabled: true,
                privileged: false,
                alwaysPullImage: false,
                workingDir: '/var/jenkins_home',
                resourceRequestCpu: '1000m',
                resourceRequestMemory: '1Gi',
                resourceLimitMemory: '1.1Gi',
        )

As to why it isn't being loaded into the proper namespace, do you have a default kubernetes plugin config setup anywhere? There are settings for both the general namespace target and individual container template namespace targets. If you have neither, the above solution to set the namespace value may be the only way

0
wolmi On

You need to check on the Jenkins admin interface the Kubernetes plugin configuration, you are able to override some parameters from de UI.