curl在kubenetes pod上运行exec命令时给出403错误



我正在尝试使用Kubernetes API在容器内执行命令。而命令使用kubectl 工作

kubectl exec shell演示-bash-c env

但当使用curl使用Kubernetes web API(kubectl代理(时,同样会出现403错误。

$ curl -k -v POST  http://192.168.1.44:5443/api/v1/namespaces/mynamespace/pods/shell-demo/exec?command=bash&command=-c&command=env&container=nginx&stderr=true&stdout=true
[1] 405247
[2] 405248
[3] 405249
[4] 405250
[5] 405251
[2]   Done                    command=-c
[3]   Done                    command=env
[4]-  Done                    container=nginx
[farooq@farooq-pc ansible-vbox-vagrant-kubernetes]$ * Could not resolve host: POST
* Closing connection 0
curl: (6) Could not resolve host: POST
*   Trying 192.168.1.44:5443...
* Connected to 192.168.1.44 (192.168.1.44) port 5443 (#1)
> GET /api/v1/namespaces/mynamespace/pods/shell-demo/exec?command=bash HTTP/1.1
> Host: 192.168.1.44:5443
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Thu, 18 Nov 2021 19:54:34 GMT
< Content-Length: 10
<
Forbidden

您的curl命令看起来是错误的。尝试在POST前面使用-X,如下所示:curl -k -v -X POST http://192.168.1.44:5443/api/v1/namespaces/mynamespace/pods/shell-demo/exec?command=bash&command=-c&command=env&container=nginx&stderr=true&stdout=true还请确保如果您需要POST,因为您不添加任何数据(-d mypostbody(,它可能是一个简单的GET请求,带有urlended-data,这也取决于您的API端点。

相关内容

最新更新