K8s:获取 HTTP 415 以向 Kubernetes REST API 服务器发送 PATCH 请求

the*_*ion 4 kubernetes kubernetes-ingress kubernetes-apiserver

我从以下链接看到 Kubernetes REST API 参考手册支持 PATCH 请求:https: //kubernetes.io/docs/reference/ generated/kubernetes-api/v1.18/#patch-ingress-v1beta1-networking-k8s -io

HTTP Request
PATCH /apis/networking.k8s.io/v1beta1/namespaces/{namespace}/ingresses/{name}
Run Code Online (Sandbox Code Playgroud)

但是,在 Postman 中通过 Kubernetes REST API 服务器向 Kubernetes 集群发送 PATCH 请求时,出现 HTTP 415 Unsupported Media Type 错误。

我想在集群外部部分更新我们指定的入口。为此,我添加了试用版的快照。

Kubernetes REST API 服务器入口 PATCH 请求

我们的 Kubernetes 版本是:

Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:13:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:50Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Run Code Online (Sandbox Code Playgroud)

修补 JSON:

{
   "apiVersion": "networking.k8s.io/v1beta1",
   "kind": "Ingress",
   "metadata": {
      "name": "demo-ingress",
      "annotations": {
         "nginx.org/rewrites": "serviceName=demo-service-235 rewrite=/"
      }
   },
   "spec": {
      "rules": [
         {
            "host": "www.demodeployment.com",
            "http": {
               "paths": [
                  {
                     "path": "/235/",
                     "backend": {
                        "serviceName": "demo-service-235",
                        "servicePort": 8088
                     }
                  }
               ]
            }
         }
      ]
   }
}
Run Code Online (Sandbox Code Playgroud)

我可以成功使用 GET、POST、PUT 和 DELETE,但在 PATCH 请求中我无法得到相同的结果。问题的根本原因可能是什么?你有什么想法?

Ben*_*gar 7

我通过设置以下标头解决了同样的问题:

"Content-Type": "application/strategic-merge-patch+json"
Run Code Online (Sandbox Code Playgroud)