Kubernetes plugin and podtemplate in declarative pipeline

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Kubernetes plugin and podtemplate in declarative pipeline

jado
Hi, 
I'm using Jenkins 2.176.2 and Kubernetes Plugin 1.18.1. 
I defined PodTemplate via GUI with RawYaml definition and i would like to use this in my declarative pipeline:

pipeline {
agent {
kubernetes {
cloud 'mycloud'
defaultContainer 'jnlp'
inheritFrom 'my-buildslave'
}
}

 However pipeline execution stucks here:
Still waiting to schedule task
All nodes of label 'run-jenkins-buildslave-on-kube_84-7gg7p’ are offline

Pod is not being created on k8s. 
When i add any yaml definition as below:


pipeline {
agent {
kubernetes {
cloud 'mycloud'
defaultContainer 'jnlp'
inheritFrom 'my-buildslave'
yaml """
spec:
containers:
- name: golang
image: golang:1.6.3-alpine
command:
- cat
tty: true
"""
}
}
 
Then POD has been started but it doesn't inherit from pod template - it runs 2 containers: jnlp and golang. How to use inheritance or some other mechanism so i dont need to define my pod in each pipeline?

My Kubernetes Pod template raw definition:
spec:      
  imagePullSecrets:
  - name: mysec
  containers:
  - name: maven                                                                
    image: maven:latest  
    imagePullPolicy: Always                                                    
    command:                                                                    
    - cat                                                                      
    tty: true
    env:
    - name: DOCKER_HOST
      value: tcp://localhost:2375
    resources: {}
 
  - name: dind
    image: docker:18.05-dind
    securityContext:
      privileged: true
    volumeMounts:
    - name: dind-storage
      mountPath: /var/lib/docker
    resources: {} 



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/64ba286e-ce44-49fb-8142-a0bb787d3137%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Kubernetes plugin and podtemplate in declarative pipeline

jado
I've tried that before with no luck, but it starts to work finally - you don't define kubernetes template in the agent section, but reference to created one by the label assigned to it: 
pipeline {
agent {
label 'buildslave'
}


W dniu środa, 11 września 2019 15:25:00 UTC+2 użytkownik jado napisał:
Hi, 
I'm using Jenkins 2.176.2 and Kubernetes Plugin 1.18.1. 
I defined PodTemplate via GUI with RawYaml definition and i would like to use this in my declarative pipeline:

pipeline {
agent {
kubernetes {
cloud 'mycloud'
defaultContainer 'jnlp'
inheritFrom 'my-buildslave'
}
}

 However pipeline execution stucks here:
Still waiting to schedule task
All nodes of label 'run-jenkins-buildslave-on-kube_84-7gg7p’ are offline

Pod is not being created on k8s. 
When i add any yaml definition as below:


pipeline {
agent {
kubernetes {
cloud 'mycloud'
defaultContainer 'jnlp'
inheritFrom 'my-buildslave'
yaml """
spec:
containers:
- name: golang
image: golang:1.6.3-alpine
command:
- cat
tty: true
"""
}
}
 
Then POD has been started but it doesn't inherit from pod template - it runs 2 containers: jnlp and golang. How to use inheritance or some other mechanism so i dont need to define my pod in each pipeline?

My Kubernetes Pod template raw definition:
spec:      
  imagePullSecrets:
  - name: mysec
  containers:
  - name: maven                                                                
    image: maven:latest  
    imagePullPolicy: Always                                                    
    command:                                                                    
    - cat                                                                      
    tty: true
    env:
    - name: DOCKER_HOST
      value: tcp://localhost:2375
    resources: {}
 
  - name: dind
    image: docker:18.05-dind
    securityContext:
      privileged: true
    volumeMounts:
    - name: dind-storage
      mountPath: /var/lib/docker
    resources: {} 



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3ca074ce-6ce1-47f0-b84a-fee101bd31f9%40googlegroups.com.