thenextgeneration
thenextgeneration

Reputation: 65

K8s: gets HTTP 415 for PATCH request to Kubernetes REST API server

I have seen that PATCH request is supported in Kubernetes REST API reference manual from this link: 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}

However, I get HTTP 415 Unsupported Media Type error when sending PATCH request to Kubernetes cluster through Kubernetes REST API server in Postman.

I want to update our specified ingress partially outside the cluster. For this purpose, I added a snapshot from my trial.

Kubernetes REST API server Ingress PATCH Request

Our Kubernetes version is:

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"}

Patching 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
                     }
                  }
               ]
            }
         }
      ]
   }
}

I can use GET, POST, PUT and DELETE successfully, in PATCH request I can't get the same results. What could be the root cause of the problem? What are your ideas?

Upvotes: 4

Views: 3776

Answers (2)

Ben Elgar
Ben Elgar

Reputation: 785

I solved this same issue by setting the following header:

"Content-Type": "application/strategic-merge-patch+json"

Upvotes: 9

Arghya Sadhu
Arghya Sadhu

Reputation: 44569

Set Content-Type: application/merge-patch+json in the header.

Also I would suggest to first try to patch using kubectl patch --v=8 with increased verbosity which will display the http request and payload being sent by kubectl to Kubernetes API Server. Then you can take the same request payload and use from postman.

Upvotes: 5

Related Questions