<p>I have a Kubernetes cluster on which is deployed a replica of <a href="https://hub.docker.com/r/accusoft/prizmdoc-server" rel="nofollow noreferrer">this</a> image (but it's not important for the sake of the question).
Now, in Powershell I need to perform one REST request against the pod. In particular I have to send a <code>PUT</code> request to the endpoint <code>http://&lt;POD_IP&gt;:18681/PCCIS/V1/Service/Properties/Servers</code> passing this JSON payload:</p>
<p><code>{&quot;servers&quot;:[{&quot;port&quot;:&quot;18682&quot;,&quot;address&quot;:&quot;10.244.1.29&quot;}]}</code></p>
<p>What I was trying to do is perform this action from within a <a href="https://hub.docker.com/r/curlimages/curl" rel="nofollow noreferrer">curlimages/curl</a> pod, just to be able to reach the pod's network. This is my attempt:</p>
<pre><code>$PrizmDocPodIP=&quot;10.244.1.29&quot;
$JsonPostBody='{&quot;servers&quot;:[{&quot;port&quot;:&quot;18682&quot;,&quot;address&quot;:&quot;10.244.1.29&quot;}]}'
$cmd = &quot;curl -i --header 'Content-Type: application/json' --request PUT --data '$JsonPostBody' http://$($PrizmDocPodIP):18681/PCCIS/V1/Service/Properties/Servers&quot;
kubectl run -i --tty --rm curl --image=curlimages/curl --restart=Never &quot;$cmd&quot;
</code></pre>
<p>Unexpectedly, the command output this error:</p>
<pre><code>curl: (3) nested brace in URL position 82:
curl -i --header 'Content-Type: application/json' --request PUT --data '{servers:[{port:18682,address:10.244.1.29}]}' http://10.244.1.29:18681/PCCIS/V1/Service/Properties/Servers
</code></pre>
<p>As you can see, the problem I have is that the string command I pass is not interpreted the right way and moreover the payload loses all the doublequotes of the JSON, that are important for the <code>curl</code> command to propertly work.</p>
<p>One another test I made is with this command (the <code>echo</code> is used to show what the <code>sh</code> command really would execute)</p>
<pre><code>kubectl run -i --tty --rm curl --image=curlimages/curl --restart=Never -- sh -c &quot;echo $cmd&quot;
</code></pre>
<p>And the output is</p>
<pre><code>curl -i --header Content-Type: application/json --request PUT --data {servers:[{port:18682,address:10.244.1.29}]} http://10.244.1.29:18681/PCCIS/V1/Service/Properties/Servers
</code></pre>
<p>Showing that the <code>cmd</code> Powershell variable loses its doublequotes when passed to <code>kubectl run</code></p>
<p>What should be the right syntax to pass the <code>$cmd</code> command as is (preserving all its quotes and chars)?</p>

gvdm
<p>I found the solution after some searching and trials.
First, I have to escape the double quotes in the <code>$JsonPostBody</code> variable.</p>
<pre><code>$PrizmDocPodIP=&quot;10.244.1.29&quot;
$JsonPostBody='{\&quot;servers\&quot;:[{\&quot;port\&quot;:\&quot;18682\&quot;,\&quot;address\&quot;:\&quot;10.244.1.29\&quot;}]}'
</code></pre>
<p>The other error is that the <code>curlimages/curl</code> Docker image executes the <code>kubectl run</code> arguments as the <code>curl</code>'s arguments, so I don't have to use the <code>curl</code> command:</p>
<pre><code>kubectl run -i --tty --rm curl --image=curlimages/curl --restart=Never -- -i --header 'Content-Type: application/json' --request PUT --data $JsonPostBody http://$($PrizmDocPodIP):18681/PCCIS/V1/Service/Properties/Servers
</code></pre>
<p>This outputs</p>
<pre><code>HTTP/1.1 200 OK
[1mDate[0m: Wed, 08 Jul 2020 13:23:30 GMT
[1mConnection[0m: keep-alive
1mContent-Length[0m: 0
</code></pre>
