How to test websocket connections to Rancher v2.x

Table of Contents


Rancher depends heavily on websocket support for UI and CLI features within Rancher as well as managing and interacting with downstream clusters. This article provides a quick test to determine if websocket connections are working from a potential downstream node or client to the Rancher server cluster.


Executing the test

First you will need to create an API token to authenticate against Rancher. Start by logging into the Rancher UI. Once logged in, navigate to the API & Keys section by clicking the user icon in the top right of the pane, then click on the API & Keys menu item. Generate a new key by clicking the Add Key button, providing a name for the token and clicking Create. Copy the bearer token to a safe location.

In a Linux shell from the desired test node execute the following, substituting the bearer token and fully qualified domain name of your Rancher endpoint with these environmental variables:

export TOKEN=<your token here>
export FQDN=<your Rancher fully qualified domain name here>

Next execute the test using the following command:

curl -s -i -N \
  --http1.1 \
  -H "Connection: Upgrade" \
  -H "Upgrade: websocket" \
  -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
  -H "Sec-WebSocket-Version: 13" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Host: $FQDN" \
  -k https://$FQDN/v3/subscribe

If websockets work this will successfully connect to the Rancher server and print a steady stream of json output reflecting configuration items being sent from the server. In the event of a failed connection this should print a meaningful error you can act upon to get websockets working between your client and Rancher server.

The below is an example of the output from the test upon a successfully established websocket:

HTTP/1.1 101 Switching Protocols
Date: Tue, 21 Jan 2020 04:54:05 GMT
Connection: upgrade
Server: openresty/
Upgrade: websocket
Sec-WebSocket-Accept: qGEgH3En71di5rrssAZTmtRTyFk=

Was this article helpful?
1 out of 1 found this helpful



Please sign in to leave a comment.