我正在尝试根据这篇 SO 帖子中给出的建议设置与 Kubernetes Pod Exec API 的 websocket 连接:如何使用 API 在 pod (kubernetes) 中执行命令? https://stackoverflow.com/questions/34373472/how-to-execute-command-in-a-pod-kubernetes-using-api。
这是我到目前为止所做的 -
- 在 Chrome 中安装了简单 Web Socket 客户端扩展。
- Started
kubectl proxy --disable-filter=true
在允许 WS 连接的情况下运行代理。kubectl.exe
版本是1.8。
- 使用的地址
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
在 Chrome 扩展程序中连接到exec
api.
当我单击“连接”时,Chrome 报告返回错误并显示消息 -
Error during WebSocket handshake: Response must not include 'Sec-WebSocket-Protocol' header if not present in request
显然,kubectl 发回空Sec-WebSocket-Protocol
响应中的标头,Chrome 对此感到不满。
我尝试更改 Simple Web Socket Client 的代码open
将空协议参数发送到 Websocket 客户端创建调用的方法,例如 -ws = new WebSocket(url, []);
诱使 Chrome 在请求中发送空标头,但 Chrome 不发送空标头。
那么可以做什么来直接连接到exec
在 Chrome 中?
这是一个已知的问题;kubectl proxy不支持网络套接字 https://github.com/kubernetes/kubernetes/issues/25126。 (您可以通过启动来轻松验证这一点kubectl proxy
然后尝试kubectl --server=http://127.0.0.1:8001 exec ...
;您将收到消息error: unable to upgrade connection: <h3>Unauthorized</h3>
如果过滤器已启用并且Error from server (BadRequest): Upgrade request required
如果过滤器被禁用)。
The 困惑 https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#so-many-proxies可能来自以下事实:kube-apiserver
proxy 确实支持 websocket,但该 proxy 与kubectl proxy
.
据我所知,你现在有 3 个选择(按难度顺序排列):
- Access
kube-apiserver
直接地。您可能需要进行身份验证kubectl proxy
现在正在为您处理
- 使用 SockJS,这就是 Kubernetes Dashboard 的作用执行功能 https://github.com/kubernetes/dashboard/pull/1939
- Fix #25126 https://github.com/kubernetes/kubernetes/issues/25126
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)