<p>I'm trying to connect on a container throw the Kubernetes WebSocket API, from a container running within Kubernetes, without any success.  </p>

<p>Install <code>wscat</code>:</p>

<pre><code>apt-get update
apt-get install -y npm
ln -s /usr/bin/nodejs /usr/bin/node
npm install -g n
n stable
npm install -g wscat
</code></pre>

<p>Exec on Kubernetes API:</p>

<pre><code>wscat -c "wss://kubernetes.default.svc.cluster.local/api/v1/namespaces/default/pods/my-pod-1623018646-kvc4b/exec?container=aws&amp;stdin=1&amp;stdout=1&amp;stderr=1&amp;tty=1&amp;command=bash" \
  --ca /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
  -H "Authorization: Bearer $(&lt;/var/run/secrets/kubernetes.io/serviceaccount/token)"
error: Error: unexpected server response (400)
</code></pre>

<p>Do you know what I'm doing wrong?</p>

<p>Note that the following works:</p>

<pre><code>curl https://kubernetes.default.svc.cluster.local/api/v1/namespaces/default/pods/my-pod-1623018646-kvc4b \
  --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
  -H "Authorization: Bearer $(&lt;/var/run/secrets/kubernetes.io/serviceaccount/token)"
</code></pre>

<p>Apparently some people are able to connect: <a href="https://stackoverflow.com/a/43841572/599728">https://stackoverflow.com/a/43841572/599728</a></p>

<p>Cheers</p>

<p>I just found out that the container name was wrong:<br>
<code>?container=aws</code> Aws was not on this pod.</p>
