<p>I'm trying to execute command in a contianer (in a Kubernetes POD on GKE with kubernetes 1.1.2). </p>

<p>Reading documentation I understood that I can use GET or POST query to open websocket connection on API endpoint to execute command. When I use GET, it does not work completly, returns error. When I try to use POST, something like that could work probably (but it's not):</p>

<pre><code>curl 'https://admin:xxx@IP/api/v1/namespaces/default/pods/hello-whue1/exec?stdout=1&amp;stderr=1&amp;command=ls' -H "Connection: upgrade" -k -X POST -H 'Upgrade: websocket'
</code></pre>

<p>repsponse for that is</p>

<pre><code>unable to upgrade: missing upgrade headers in request: http.Header{"User-Agent":[]string{"curl/7.44.0"}, "Content-Length":[]string{"0"}, "Accept":[]string{"*/*"}, "Authorization":[]string{"Basic xxx=="}, "Connection":[]string{"upgrade"}, "Upgrade":[]string{"websocket"}}
</code></pre>

<p>Looks like that should be enough to upgrade post request and start using websocket streams, right? What I'm missing?</p>

<p>I was also pointed that opening websocket with POST is probably violation of websocket protocol (only GET should work?).</p>

<p>Also</p>

<p>Use websocket client it's work.</p>

<p>In my local kuberenetes cluster, the connection metadata like this:</p>

<pre><code>ApiServer = "172.21.1.11:8080"
Namespace = "default"
PodName = "my-nginx-3855515330-l1uqk"
ContainerName = "my-nginx"
Commands = "/bin/bash"
</code></pre>

<p>the connect url:</p>

<pre><code>"ws://172.21.1.11:8080/api/v1/namespaces/default/pods/my-nginx-3855515330-l1uqk/exec?container=my-nginx&amp;stdin=1&amp;stdout=1&amp;stderr=1&amp;tty=1&amp;command=%2Fbin%2Fbash"
</code></pre>

<p>On maxos, a wsclient CLI tool: <a href="https://blog.grandcentrix.net/a-command-line-websocket-client/" rel="nofollow noreferrer">wscat</a>, you can use it as a test tool:</p>

<p><a href="https://i.stack.imgur.com/Q3NOz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q3NOz.jpg" alt="enter image description here"></a></p>

<p>You can access the websocket example: "<a href="https://github.com/lth2015/container-terminal" rel="nofollow noreferrer">https://github.com/lth2015/container-terminal</a>"</p>
