<p>I am writing a script which gets a pod ip and writes it into a python file in another pod
This is how i got my pod ip :</p>
<pre><code>database=$(kubectl get svc database --namespace=namespace_name|sed -n -e '2p' |awk '{print $3}')
</code></pre>
<p>This is how i am trying to write it into a text file in another pod:</p>
<pre><code>kubectl exec -it --namespace=namespace_name pod_name -- sed -i 's/ip_addr/$postgres/' conf.py
</code></pre>
<p>it gets executed but the python file is not edited</p>

Tony Frank
<p>In your question, you are setting the database variable but using postgres in the pod for replacement. That will never work.</p>
<p><strong>Try this (notice the double quotes for variable expansion):</strong></p>
<pre><code>kubectl exec --namespace=namespace_name pod_name -- sed -i &quot;s/ip_addr/$postgres/&quot; conf.py
</code></pre>
<p><strong>Another option:</strong></p>
<p>Create the file locally with all the values replaced then just copy the file to the pod using</p>
<pre><code>kubectl cp --namespace=namespace_name &lt;local-path&gt;/conf.py pod_name:&lt;pod-path&gt;/conf.py
</code></pre>
