Jenkins pipeline job keeps on creating pods inside kubernetes cluster

10/1/2020

Recently I have been trying to setup a pipeline inside jenkins. The aim is to create a pod and perform kubernetes deployment.

But when i run the pipeline job it keeps on creating pods one after another, it never completes the job -

enter image description here

Here are steps -

  1. Setup the kubernetes cluster - successfully
  2. Installed jenkins - successfully
  3. Connected jenkins to kubernetes cluster - successfully
  4. Here is the pipeline script -
pipeline {
  agent {
    kubernetes {
      //cloud 'kubernetes'
      yaml """
kind: Pod
metadata:
  name: kaniko
spec:
  containers:
  - name: jhooq-pod-with-pvc
    image: rahulwagh17/kubernetes:jhooq-k8s-springboot
    imagePullPolicy: Always
"""
    }
  }
  stages {
      stage('build') {
          steps {
              echo "Hello World!"
          }
      }
  }
}

Not - Pods are getting created successfully and kubernetes deployment is also successful but the jenins pipeline never stops.

And my jenkins in connected to kubernetes without any issues.

enter image description here

Any suggestions or input will be highly appreciated.

-- Rahul Wagh
jenkins
jenkins-pipeline
kubernetes

1 Answer

10/1/2020

It is probably because, your Jenkins agent is not connecting to your master.

This you can validate in the node monitoring under Manage Jenkins. It should be something like below:

Jenkins Agent Provisioning

-- Vijay Daswani
Source: StackOverflow