如何使用API​​在pod(kubernetes)中执行命令? [英] How to execute command in a pod (kubernetes) using API?

查看:183
本文介绍了如何使用API​​在pod(kubernetes)中执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在contianer中执行命令(在kubernetes 1.1.2中的KKE上的KOBernetes POD上)。

阅读文档我明白我可以使用GET或POST查询在API端点上打开websocket连接来执行命令。当我使用GET时,它不能正常工作,返回错误。当我尝试使用POST时,可能会发生这样的事情(但事实并非如此):

  curl'https:// admin :xxx @ IP / api / v1 / namespaces / default / pods / hello-whue1 / exec?stdout = 1& stderr = 1& command = ls'-HConnection:upgrade-k -X POST -H'Upgrade: websocket'

对此的回应是

 无法升级:请求中缺少升级标头:http.Header {User-Agent:[] string {curl / 7.44.0},Content-Length:[] string {0},Accept:[] string {* / *},Authorization:[] string {Basic xxx ==},Connection:[] string {upgrade} ,Upgrade:[] string {websocket}} 

看起来应该足够升级发布请求并开始使用websocket流,对吧?我错过了什么?



我还指出,用POST打开websocket可能违反了websocket协议(只有GET应该可以工作?)。
$ b

另外

解决方案

您可能会有最好的时间使用 Kubernetes客户端库,它与Kubectl使用的代码相同,但如果是某些原因不是一种选择,比我最好的建议是浏览客户端库的执行远程命令的代码并查看它设置的标头。


I'm trying to execute command in a contianer (in a Kubernetes POD on GKE with kubernetes 1.1.2).

Reading documentation I understood that I can use GET or POST query to open websocket connection on API endpoint to execute command. When I use GET, it does not work completly, returns error. When I try to use POST, something like that could work probably (but it's not):

curl 'https://admin:xxx@IP/api/v1/namespaces/default/pods/hello-whue1/exec?stdout=1&stderr=1&command=ls' -H "Connection: upgrade" -k -X POST -H 'Upgrade: websocket'

repsponse for that is

unable to upgrade: missing upgrade headers in request: http.Header{"User-Agent":[]string{"curl/7.44.0"}, "Content-Length":[]string{"0"}, "Accept":[]string{"*/*"}, "Authorization":[]string{"Basic xxx=="}, "Connection":[]string{"upgrade"}, "Upgrade":[]string{"websocket"}}

Looks like that should be enough to upgrade post request and start using websocket streams, right? What I'm missing?

I was also pointed that opening websocket with POST is probably violation of websocket protocol (only GET should work?).

Also

解决方案

You'll probably have the best time using the Kubernetes client library, which is the same code the Kubectl uses, but if for some reason that isn't an option, than my best suggestion is to look through the client library's code for executing remote commands and seeing what headers it sets.

这篇关于如何使用API​​在pod(kubernetes)中执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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