<p>Its possible to set a var for a pod using a command that has to run inside of that pod? </p>

<p>what i am trying to do is get private and public ip from the node, so i can use them into the app on the allowed host, i can get the private ip using this:</p>

<pre><code>containers:
- env:
  - name: NODE_IP
    valueFrom:
      fieldRef:
         status.hostIP
</code></pre>

<p>but only that private ip, and i need the public, my idea is to get them from here:</p>

<p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html</a>
with this 2 commands:</p>

<pre><code>curl http://169.254.169.254/latest/meta-data/local-ipv4
curl http://169.254.169.254/latest/meta-data/public-ipv4
</code></pre>

<p>doing inside the container will be something like this:</p>

<pre><code>command: MYPRIVATEIP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
command: MYPUBLICIP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)

containers:
- env:
  - name: NODE_IP
    valueFrom:
      fieldRef:
         status.hostIP
</code></pre>

<p>i already try to put this like this:</p>

<pre><code>    env:
    - name: MYIP
      value: $(curl http://169.254.169.254/latest/meta-data/local-ipv4)
</code></pre>

<p>but this doesnt make anything but putting this like plane text. </p>

<p>what i expect is to have that command output inside of the var so my app can pickup from there and add into the allowed host. thanks in advance for any help! regards</p>

Lucas Carrizo
<p>I think you can use lifecycle events to achieve this. You can read about them here. <a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/</a>.</p>

<p>So I am suggesting you to create a shell script init.sh to export all the environment variables you need and run it once the pod is started.</p>

<pre><code>spec:
  containers:
  - name: container-name
    image: image-name
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "/init.sh"]
</code></pre>

<p>You can include the init.sh file in the docker image when you build the image using COPY command.</p>
