# Kubernetes agent does not inherit from default pod template

**URL:** <https://community.jenkins.io/t/kubernetes-agent-does-not-inherit-from-default-pod-template/4560>\
**Category:** Using Jenkins\
**Created:** [November 14, 2022, 10:37am UTC](https://community.jenkins.io/t/kubernetes-agent-does-not-inherit-from-default-pod-template/4560 "2022-11-14T10:37:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaunusa](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jaunusa/32/2711_2.png) [@jaunusa](https://community.jenkins.io/u/jaunusa)\
**Post date:** [November 14, 2022, 10:37am UTC](https://community.jenkins.io/t/kubernetes-agent-does-not-inherit-from-default-pod-template/4560/1 "2022-11-14T10:37:41Z")

</div>

Hi, trying to inherit container/pod configuration from default global template (kubernetes clouds config) in a declarative pipeline I got following results:

Using **yaml** with **unexpected results** :

- environment variables aren’t inherited from global pod templates
- resources aren’t inherited from global pod template

Using deprecated **containerTemplate** works:

- environment variables are inherited from global pod templates
- resources are inherited from global pod templates

But for both variants, the **volume mounts** defined globally in default pod template are inherited.

The documentation says:  
_Note that it was previously possible to define containerTemplate but that has been deprecated in favor of the yaml format._

I’m really confused, containerTemplate is the only config that works as expected but is deprecated since more than 2 years.

So has anybody an idea how to setup a declarative pipeline with inherited container config which will still work in the future (not deprecated)?

---

<div class="post-metadata">

**Author:** ![jaunusa](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jaunusa/32/2711_2.png) [@jaunusa](https://community.jenkins.io/u/jaunusa)\
**Post date:** [December 6, 2022, 10:46am UTC](https://community.jenkins.io/t/kubernetes-agent-does-not-inherit-from-default-pod-template/4560/2 "2022-12-06T10:46:12Z")

</div>

At the end I successfully passed globally defined environment variables in Jenkins to containers by mapping the values in pipeline environment:

```auto
pipeline {
   agent {
      kubernetes {
          ...
      }
   }
   environment {
      HTTPS_PROXY="${HTTPS_PROXY}"
      HTTP_PROXY="${HTTP_PROXY}"
      NO_PROXY="${NO_PROXY}"
   }
   stages {
      stage ("build") {
         container("nodejs"){
            //env.HTTPS_PROXY available
   }
}

```

Good advices in working with pod templates can be found in this article:

> **[Understanding Pod Template Inheritance](https://docs.cloudbees.com/docs/cloudbees-ci-kb/latest/cloudbees-ci-on-modern-cloud-platforms/understanding-pod-template-inheritance)**
>
> This article will guide you towards the various ways of defining a pod template.

But sometimes you don’t get around defining values globally, e.g. http proxy.

Hopefully this helps people searching undocumented features like this.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [December 7, 2022, 1:49pm UTC](https://community.jenkins.io/t/kubernetes-agent-does-not-inherit-from-default-pod-template/4560/3 "2022-12-07T13:49:36Z")

</div>

Hello @jaunusa and welcome to this community 👋 .

Thanks a lot for your feedback, that will help others facing the same problem in the future. 👍
