Jenkins not able to create kubernetes POD

12/12/2019

I'm running jenkins jobs to build our maven application and deploy into kubernetes cluster. in-order do that i have created pod container template to deploy my modules.

When i am running to build my jenkins job, my build got failed with below error,

Still waiting to schedule task
Jenkins’ doesn’t have label ‘Angular_71-bt2f0

At the same time when i am checking kubernetes master, i can able to see pods is trying to schedule and its going back to terminating state after few seconds.

root@poc:/var/run# kubectl get pods
NAME                           READY   STATUS              RESTARTS   AGE
angular-71-bt2f0-ns772-4rmrq   0/3     ContainerCreating   0          1s

root@poc:/var/run# kubectl get pods
NAME                           READY   STATUS        RESTARTS   AGE
angular-71-bt2f0-ns772-4rmrq   2/3     Terminating   0          28s
angular-71-bt2f0-ns772-mcv9z   2/3     Error         0          8s

pipeline script

def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(containers: [
    containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
    containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')
  ]) {

    node(POD_LABEL) {
        stage('Get a Maven project') {
            git 'https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage('Build a Maven project') {
                    sh 'mvn -B clean install'
                }
            }
        }
    }
  }

Please find the below master machine configuration

root@poc:~# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP          2d

root@poc:~# kubectl get nodes
NAME          STATUS    ROLES    AGE    VERSION
poc-worker2   Ready    worker   6m3s   v1.17.0
poc.com       Ready    master   2d     v1.17.0

root@poc:~# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP          2d

root@poc:~# kubectl cluster-info
Kubernetes master is running at https://10.0.0.4:6443
KubeDNS is running at https://10.0.0.4:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

kubectl error log

kubectl logs angular-71-bt2f0-ns772-4rmrq 

error: a container name must be specified for pod angular-77-l32fr-sfxqk-qhdgf, choose one of: [maven golang jnlp]
Below is the kubectl logs while running jenkins job

root@poc:~# kubectl logs angular103f578nkcrnfx69fk c maven
Error from server (NotFound): pods "angular103f578nkcrnfx69fk" not found

root@poc:~# kubectl logs angular103f578nkcrnfx69fk c golang
Error from server (NotFound): pods "angular103f578nkcrnfx69fk" not found

root@poc:~# kubectl logs angular103f578nkcrnfx69fk c jnlp
Error from server (NotFound): pods "angular103f578nkcrnfx69fk" not found

can you please some one help me how to fix this issue, i am not sure where i am doing wrong here.

-- Anonymuss
jenkins
kubernetes

1 Answer

1/12/2020

Because, kubectl -n jenkins-namespace get services shows :

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
cicd-jenkins         ClusterIP   172.20.120.227   <none>        8080/TCP    128d
cicd-jenkins-agent   ClusterIP   172.20.105.189   <none>        50000/TCP   128d

You have to go to Jenkins > Manage Jenkins > Configure System (http://jenkins:8080/configure). Then, configure Jenkins URL and jenkins tunnel accordingly (see screenshot below )

CREDITS to https://youtu.be/MkzCVvlpiaM

enter image description here

-- Abdennour TOUMI
Source: StackOverflow