Answers: <blockquote>
    <p>the definition of the replicated pods are always a copy-paste of a pod template file</p>
  </blockquote>
  
  <p>This behavior is implemented by Kubernetes itself: it takes the <code>template</code> part of the deployment spec and creates <code>replicas</code> identical pods.</p>
  
  <p>The corollary to this is that you don't need to manually write out the pod spec as a separate object.  Including it in the <code>template</code> part of a deployment (job, statefulset, daemonset) is enough.</p>
  
  <blockquote>
    <p>Is it possible to rather use a reference to the yaml file (or an url) defining a pod</p>
  </blockquote>
  
  <p>No, individual Kubernetes objects must be self-contained (except where there are facilities to do things like inject Secret values into environment variables).  The Kubernetes server doesn't know about your local file system.</p>
  
  <p>Using one of the templating systems out there (<a href="https://helm.sh/" rel="nofollow noreferrer">Helm</a> is more-or-less standard but not the only choice) could help reduce this duplication, if you really need near-identical deployments and also bare pods.  You could write something like</p>
  
  <pre><code>---
  apiVersion: v1
  kind: Pod
  {{ template "pod-spec" . }}
  ---
  apiVersion: apps/v1
  kind: Deployment
  spec:
    template:
  {{ include "pod-spec" . | trim | indent 4 }}
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-10-11T13:34:43.093Z
Answers: 2019-10-11T13:34:43.093Z
Answers: David Maze
Answers: <p>Yes you can create resources (including pods) from a url yaml using <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#creating-objects" rel="nofollow noreferrer">kubectl</a>.  However, just because you pointed to a remote url does not mean that the resource will automatically update.  You will need to either re-deploy when the remote yaml is updated, develop/integrate with a service that handles this, or look into using a tool such as <a href="https://github.com/helm/helm/blob/master/docs/using_helm.md" rel="nofollow noreferrer">helm</a> to help manage changes.</p>
  
  <p>It does not need to be avoided, you just need to know that it will not automatically update if the source changes.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-10-07T10:58:53.850Z
Answers: My question is: if it's possible to use a reference file or URL inside a Deployment description file rather than writing the whole pod description. I'm not really sure if you're answering that because for me kubectl is the cli, and doesn't necessarily means using a file. Could you provide an exemple of a Deployment description file where the pod definition uses a reference to a file (or URL) ?
Answers: Asoub
Answers: CC BY-SA 4.0
Answers: 2019-10-03T11:52:05.627Z
Answers: 2019-10-03T11:52:05.627Z
Answers: Wesley Rolnick
Body: <p>I've been looking at Deployments descriptions in Kubernetes. In the tutorials I've found, the definition of the replicated pods are always a copy-paste of a pod template file.</p>
  
  <p>Is it possible to rather use a reference to the yaml file (or an url) defining a pod (I didn't found any resource telling so)?</p>
  
  <p>If yes, should it be avoided (in order to keep label/selector in the same file for example)?</p>
  
  <p>If no, is there a reason (because Kubernetes wouldn't know if you modified the pod template file for example)?</p>
  
Tags: <kubernetes>
Title: Use a pod template file in a Deployment
UserDisplayName: Asoub
ThreadText: # Use a pod template file in a Deployment
  
  (Asked by: username_0 on 2019-10-03)
  
  I've been looking at Deployments descriptions in Kubernetes. In the tutorials I've found, the definition of the replicated pods are always a copy-paste of a pod template file.
  
  Is it possible to rather use a reference to the yaml file (or an url) defining a pod (I didn't found any resource telling so)?
  
  If yes, should it be avoided (in order to keep label/selector in the same file for example)?
  
  If no, is there a reason (because Kubernetes wouldn't know if you modified the pod template file for example)?
  
  **Tags:** kubernetes
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-10-11. Score: 1 | Accepted answer
  
  > the definition of the replicated pods are always a copy-paste of a pod template file
  
  This behavior is implemented by Kubernetes itself: it takes the `template` part of the deployment spec and creates `replicas` identical pods.
  
  The corollary to this is that you don't need to manually write out the pod spec as a separate object. Including it in the `template` part of a deployment (job, statefulset, daemonset) is enough.
  
  > Is it possible to rather use a reference to the yaml file (or an url) defining a pod
  
  No, individual Kubernetes objects must be self-contained (except where there are facilities to do things like inject Secret values into environment variables). The Kubernetes server doesn't know about your local file system.
  
  Using one of the templating systems out there ([Helm](https://helm.sh/) is more-or-less standard but not the only choice) could help reduce this duplication, if you really need near-identical deployments and also bare pods. You could write something like
  
  ```
  ---
  apiVersion: v1
  kind: Pod
  {{ template "pod-spec" . }}
  ---
  apiVersion: apps/v1
  kind: Deployment
  spec:
    template:
  {{ include "pod-spec" . | trim | indent 4 }}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2019-10-03. Score: 1
  
  Yes you can create resources (including pods) from a url yaml using [kubectl](https://kubernetes.io/docs/reference/kubectl/cheatsheet/#creating-objects). However, just because you pointed to a remote url does not mean that the resource will automatically update. You will need to either re-deploy when the remote yaml is updated, develop/integrate with a service that handles this, or look into using a tool such as [helm](https://github.com/helm/helm/blob/master/docs/using_helm.md) to help manage changes.
  
  It does not need to be avoided, you just need to know that it will not automatically update if the source changes.
  
  > **Comments:**
  > **username_0**: My question is: if it's possible to use a reference file or URL inside a Deployment description file rather than writing the whole pod description. I'm not really sure if you're answering that because for me kubectl is the cli, and doesn't necessarily means using a file. Could you provide an exemple of a Deployment description file where the pod definition uses a reference to a file (or URL) ?  
  
  ---
  
  