Kubernetes jenkins pod template creating pod in wrong namespace

4/5/2019

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.

-- smk
jenkins
kubernetes
kubernetes-jenkins-plugin

3 Answers

4/5/2019

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

-- pypalms
Source: StackOverflow

4/5/2019

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

-- wolmi
Source: StackOverflow

4/5/2019

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
-- Orlando G.
Source: StackOverflow