In the kubernetes API, how does the portforwarding endpoint work?
In theory it should be enough to create a websocket connection to the endpoint like this:
websocat tcp-listen:0.0.0.0:8888 ws://localhost:8001/api/v1/namespaces/worker/pods/worker-0/portforward?ports=8080
Unfortunately if I do so a curl to 8888 fails:
$ curl -v -XPOST -H "X-Stream-Protocol-Version: portforward.k8s.io" -H "User-Agent: kubectl/v1.27.4 (linux/amd64) kubernetes/fa3d799" 'http://localhost:8888/api/v1/namespaces/worker/pods/worker-0/portforward'
* Trying 127.0.0.1:8888...
* Connected to localhost (127.0.0.1) port 8888 (#0)
> POST /api/v1/namespaces/worker/pods/worker-0/portforward HTTP/1.1
> Host: localhost:8888
> Accept: */*
> X-Stream-Protocol-Version: portforward.k8s.io
> User-Agent: kubectl/v1.27.4 (linux/amd64) kubernetes/fa3d799
>
* Received HTTP/0.9 when not allowed
* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed
A regular kubectl port-forward works fine. Above I tried to recreate that call as close as possible, but it fails.
What part of the interaction did I miss? Are you aware of any good documentation/examples for this API call?
Are you aware of any library that already solved that issue and allows me to use the connection directly without binding it to a local port first?