Kubernetes pod exec API异常:如果请求中不存在响应,则响应中不得包含"Sec-WebSocket-Protocol"标头 [英] Kubernetes pod exec API exception: Response must not include 'Sec-WebSocket-Protocol' header if not present in request

查看:471
本文介绍了Kubernetes pod exec API异常:如果请求中不存在响应,则响应中不得包含"Sec-WebSocket-Protocol"标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据此SO帖子中给出的建议尝试建立与Kubernetes Pod Exec API的Websocket连接:

I am trying to setup a websocket connection to the Kubernetes Pod Exec API, based on the suggestions given in this SO post: How to execute command in a pod (kubernetes) using API?. Here's what I have done so far -

  1. 在Chrome中安装了Simple Web Socket客户端扩展程序.
  2. 启动kubectl proxy --disable-filter=true以在允许WS连接的情况下运行代理. kubectl.exe版本是1.8.
  3. Chrome扩展程序中使用的地址ws://localhost:8001/api/v1/namespaces/default/pods/nginx-3580832997-26zcn/exec?container=nginx&stdin=1&stdout=1&stderr=1&tty=1&command=%2Fbin%2Fsh连接到exec api.
  1. Installed Simple Web Socket Client extension in Chrome.
  2. Started kubectl proxy --disable-filter=true to run proxy with WS connections allowed. kubectl.exe version is 1.8.
  3. Used address ws://localhost:8001/api/v1/namespaces/default/pods/nginx-3580832997-26zcn/exec?container=nginx&stdin=1&stdout=1&stderr=1&tty=1&command=%2Fbin%2Fsh in the Chrome extension to connect to the exec api.

当我单击连接"时,Chrome会报告错误并显示错误消息-

When I click connect, Chrome reports back an error with the message -

Error during WebSocket handshake: Response must not include 'Sec-WebSocket-Protocol' header if not present in request

很明显,kubectl在响应中发回了空的Sec-WebSocket-Protocol标头,而Chrome正在对此进行冒犯.

Apparently, kubectl is sending back empty Sec-WebSocket-Protocol header in the response and Chrome is taking offense to that.

我尝试更改简单Web套接字客户端open方法的代码,以将空协议参数发送到Websocket客户端创建调用,例如-ws = new WebSocket(url, []);哄骗Chrome发送请求中的空标头,但Chrome不发送空标题.

I tried changing the code of Simple Web Socket Client open method to send empty protocols parameter to the Websocket client creation call, like - ws = new WebSocket(url, []); to coax Chrome in sending empty header in request, but Chrome doesn't send empty header.

那么在Chrome中直接连接到exec怎么办?

So what can be done to directly connect to the exec in Chrome?

推荐答案

阅读

After reading the code in https://github.com/kubernetes-ui/container-terminal/blob/master/container-terminal.js, found that exec uses base64.channel.k8s.io protocol. The Simple Web Socket Client code wouldn't have worked because of this and also that the stream communication is in base64, not plain text.

这是其他尝试实现基于WS的终端仿真器的人的答案...正如@ janos-lenart所提到的,代码很新,在不同的浏览器中使用它可能会出现问题,这是最好的选择是要阅读示例代码并从此处开始.

Leaving this as an answer for other folks trying to implement a WS based terminal emulator... as @janos-lenart mentioned, the code is pretty new and there may be issues using it in different browsers, best bet at this point is to read example code and start from there.

这篇关于Kubernetes pod exec API异常:如果请求中不存在响应,则响应中不得包含"Sec-WebSocket-Protocol"标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆