0

I have created kubernetes cluster in GCP and top of it i have configured jenkins in kubernetes using the below url https://cloud.google.com/solutions/jenkins-on-kubernetes-engine-tutorial

I am able to run jenkins build with normal commands and it is creating a pod and the build is getting successful. When i am trying to change the image for maven build or golang build, i am unable to complete it. When i try to change it the pod is keep on terminating and recreating.

jenkins kubernetes configuration

Jenkins pod template

Jenkins build

  • I guess you're asking for what is going wrong? Did you try to take a look for the pod which is terminating and recreating? – Manuel Jan 21 '21 at 22:24
  • What are the log saying? What is kubectl describe pod saying? – Manuel Jan 21 '21 at 22:30
  • Yes i have described the pod, It shows nothing it is simply creating and killing the pod. No other error. – sai manikanta Jan 22 '21 at 05:49
  • It's hardly possible there is not any info in logs ? Did you try to run `kubectl logs ` ? Also when you describe such failing `Pod`, did you look at the `events` section ? If it crashes, it does it for some reason. Could you share your `Pod`/`Deployment` definition yaml ? – mario Jan 22 '21 at 13:43
  • I have tried giving custom image in pod template section in jenkins UI, but still it is taking default jnlp image. I tried both in jenkins Ui and pipeline script. Is there any way to pull our custom image and to run jenkins pipeline job. Because my pipeline job depend on goland and some other dependencies. – sai manikanta Jan 22 '21 at 20:58
  • I have this setup running on my home cluster. i compared your setup and mine. First, the kubernetes cluster url is my external ip https://ip:6443. Jenkins Url: Check your svc and use the whole name of the svc including the namespace like http://jenkins.namespace.svc.cluster.local:8080. Same for the tunnel be sure, that you have set a svc on port 50000 and that your jenkins pod is serving the same. further i gues you need credentials for your cluster. That's what i needed to set it up. – Manuel Jan 22 '21 at 21:45
  • you also need to disable the https certificate check. – Manuel Jan 22 '21 at 21:52
  • whatever you have mentioned, everything is correct and working. But still pod keeps on creating. can we customise the jenkins/slave jnlp image based on our requirement. – sai manikanta Jan 22 '21 at 22:45
  • Get it running first. The communication between the slave pods and your Jenkins master is broken. Fix this first, get it running then you still can customize it. But actually there's no need, to customize this. – Manuel Jan 25 '21 at 07:19
  • Hey it is working now, thanks!! I have created a pod template in Jenkins pipeline by referring this url https://github.com/jenkinsci/kubernetes-plugin/blob/kubernetes-1.18.2/README.md – sai manikanta Jan 26 '21 at 00:06
  • Could you post it as an answer then and mark it as **accepted** ? It will be more visible for others. – mario Jan 27 '21 at 12:07

1 Answers1

2

We can add pod template in Jenkins pipeline script to pull our custom image and to run as a slave pod. Use this below format:

pipeline {
  agent {
    kubernetes {
      defaultContainer 'jnlp'
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: maven
    image: maven:alpine
    command:
    - cat
    tty: true
  - name: busybox
    image: busybox
    command:
    - cat
    tty: true
"""
    }
  }
  stages {
    stage('Run maven') {
      steps {
        container('maven') {
          sh 'mvn -version'
        }
        container('busybox') {
          sh '/bin/busybox'
        }
      }
    }
  }
}
  • am new to kubernetes. May i know where to add this pipeline and how can we call this pipeline when any job is getting triggered. because if any job is getting triggered then as per the slave lable this pipeline should be invoked right? – Ramesh Thiyagarajan Aug 24 '23 at 04:32