Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes pod exec API - Upgrade request required

I am trying to get the POST and GET requests working (via Postman) but this is what I'm getting,

GET Request

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

GET Response

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

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

  },
  "code": 404
}

POST Request

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

POST Response

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

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

Any idea on how to get these requests working? What parameters need to be changed?

Thanks

like image 349
Mujeeb Avatar asked Feb 05 '23 01:02

Mujeeb


1 Answers

I think you are trying to exec into a pod. A websocket connection is required if you want to exec into a pod.

For a websocket connection, an http(s) call is made first, followed by an upgrade request to websocket using the HTTP Upgrade header.

curl does not support upgrade from http to websocket. Hence the error.

kubectl exec would be handy for this use case.

You can also try other cli tools which support websockets, like

  • wscat
like image 149
Nizar M Avatar answered Feb 11 '23 22:02

Nizar M