<p>I would like to create a yaml once the k8s pod is up, in my previous attempt, I just upload the yaml file and use wget to download it.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
    - name: p-test
      image: p-test:latest
      command:
        - sh
        - '-c'
        - &gt;-
          wgethttps://ppt.cc/aId -O labels.yml
      image: test/alpine-utils

</code></pre>
<p>In order to make it more explicit, I try to use heredoc to embed the content of <code>labels.yml</code> into the k8s pod manifest, like:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
    - name: p-test
      image: p-test:latest
      command:
        - &quot;/bin/bash&quot;
        - '-c'
        - &gt; 
          cat &lt;&lt; LABEL &gt; labels.yml

          key: value

          LABEL
</code></pre>
<p>But it doesn't work, please suggest how to modify it, thanks.</p>

good5dog5
<p>Instead of playing with <code>heredoc</code> in pod definition, it's much better and convenient to define your <code>yaml</code> file in <a href="https://kubernetes.io/docs/concepts/configuration/configmap/" rel="nofollow noreferrer">the ConfigMap</a> and refer to it in your pod definition (mount it as volume and <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">use <code>subPath</code></a>) - like in this example (I changed <code>p-test</code> image into <code>nginx</code> image):</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: my-configmap
data:
  labels.yaml: |-
    key: value
---
apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
    - name: p-test
      image: nginx:latest
      volumeMounts:
      - name: my-configmap-volume
        mountPath: /tmp/labels.yaml
        subPath: labels.yaml
  volumes:
  - name: my-configmap-volume
    configMap:
      name: my-configmap
</code></pre>
<p>Then on the pod you will find your <code>labels.yaml</code> in the <code>/tmp/labels.yaml</code>.</p>
