Kubernetes API using websocket from NodeJS

9/15/2016

I am writing a NodeJS application which is supposed to get deploymentstatuses from the Kubernetes API using the websocket transport layer.

For this I use the socket.io-client module and I connect with the following snippet:

    var url = 'wss://myurl:8443?watch=true&access_token=myaccesstoken';
    var socket = ioClient.connect(url, {
      reconnect: true,
      transports        : ['websocket'],
      path              : "/api/v1/namespaces/mynamespace/replicationcontrollers",
      secure            : true,
      rejectUnauthorized: false,
      verify            : false});

This however gives me an unexpected error, 403. Testing this in extensions like Websocket Client to Chrome works perfectly fine. Also I receive a 200 if I try a path with less sensetive data, but not an upgrade to websocket.

I read somewhere the Kubernetes API doesn't treat the WebSocket-protocol correctly, perhaps this is related? I have also tried with other more native libraries to Node such as websocket and ws with the same result.

-- Undrium
kubernetes

1 Answer

11/19/2018

When adding a ?watch=true in a Kubernetes API call, the request does not use WebSocket's but instead will stream / chunk the response over the HTTP connection.

-- Samuel
Source: StackOverflow