2
votes

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?

2
could you share what kind of data you are patching? if possible share json file whihc you are patching? - Dashrath Mundkar
I will, but I think that it is not related to patching because whatever I write, I always get the same error. - thenextgeneration
Fwiw, I'm also encountering this on 1.18 - Ben Elgar

2 Answers

4
votes

I solved this same issue by setting the following header:

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

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.