Kubernetes exec throw the WebSocket API

6/6/2017

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

Install wscat:

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

Exec on Kubernetes API:

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

Do you know what I'm doing wrong?

Note that the following works:

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 $(</var/run/secrets/kubernetes.io/serviceaccount/token)"

Apparently some people are able to connect: https://stackoverflow.com/a/43841572/599728

Cheers

-- Joan
kubernetes

1 Answer

6/7/2017

I just found out that the container name was wrong:
?container=aws Aws was not on this pod.

-- Joan
Source: StackOverflow