how can i use RestApi to update deployment in k8s?

6/28/2018

I want to use the RestApi to update the deployment. and I test it with postman, but always got 415 back.


the info is as follows:

type: PATCH

url: https://k8sClusterUrl:6443/apis/extensions/v1beta1/namespaces/ns/deployments/peer0

header:

Authorization: bearer token  
Content-Type:application/json  

body:

{
    "kind": "Deployment",
    "spec":
    {
        "template":
        {
            "spec":
            {
                "containers":[
                    {
                        "$setElementOrder/volumeMounts":[{"mountPath":"/host/var/run/"},{"mountPath":"/mnt"}],
                        "name":"peer0",
                        "image":"hyperledger/fabric-peer:x86_64-1.1.0"}
                ]
            }
        }
    }
}

response:

{
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Failure",
    "message": "the server responded with the status code 415 but did not return more information",
    "details": {},
    "code": 415
}

I have muti-containers in this pod, and only want to apply for the specific container: peer0.
Any different for the $setElementOrder var?

-- ling
deployment
kubernetes
postman

2 Answers

2/28/2020

You can try using body and using Content-Type to application/json-patch+json, method PATCH:

[{
"op" : "replace",
"path" : "/spec/template/spec/container/0/$setElementOrder/volumeMounts",
"value" : "<value you want to replace>"
}]
-- Achyut
Source: StackOverflow

6/28/2018

415 is invalid media type.

In this case, you should be setting the media type as application/json+patch+json (you can see this in the documentation here)

-- Jeff Foster
Source: StackOverflow