【问题标题】:Kubernetes pod exec API - Upgrade request requiredKubernetes pod exec API - 需要升级请求
【发布时间】:2020-10-12 19:36:41
【问题描述】:

我正在尝试使 POST 和 GET 请求正常工作(通过 Postman),但这就是我得到的,

GET 请求

curl -X GET http://localhost:8080/api/v1/namespaces/default/pods/mypod/exec

获取响应

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "the server could not find the requested resource",
  "reason": "NotFound",
  "details": {

  },
  "code": 404
}

POST 请求

curl -X POST 'http://localhost:8080/api/v1/namespaces/default/pods/mypod/exec?command=ls&container=my-container&stderr=true&stdout=true'

POST 响应

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "Upgrade request required",
  "reason": "BadRequest",
  "code": 400
}

知道如何让这些请求生效吗?需要更改哪些参数?

谢谢

【问题讨论】:

    标签: kubernetes postman


    【解决方案1】:

    我认为您正在尝试执行到 pod 中。如果要执行到 pod 中,则需要 websocket 连接。

    对于 websocket 连接,首先进行 http(s) 调用,然后使用 HTTP Upgrade 标头向 websocket 发出升级请求。

    curl 不支持从 http 升级到 websocket。因此错误。

    kubectlexec 对于这个用例会很方便。

    你也可以试试其他支持 websocket 的 cli 工具,比如

    【讨论】:

    • 是的,通过 curl 无法实现,所以我们使用 kubectl 代替。
    【解决方案2】:
    wscat -n --header "Authorization: Bearer $TOKEN"   -c 'https://200.200.200.160:6443/api/v1/namespaces/default/pods/mysql/exec?command=bash&container=mysql&stdin=true&stdout=true&tty=true'
    

    wscat:https://github.com/websockets/wscat

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 2018-12-13
      • 2020-03-01
      • 1970-01-01
      • 2021-01-26
      相关资源
      最近更新 更多