Search code examples
kuberneteskubectl

Kubectl Patch Error: does not contain declared merge key: name


Trying to update the resources of my Deployment using kubectl patch command:

kubectl patch statefulset test -n test --patch '{"spec": {"template": {"spec": {"containers": [{"resources": [{"limits": [{"cpu": "4000m","memory": "16Gi"}]},{"requests": [{"cpu": "3000m","memory": "13Gi"}]}]}]}}}}'

But getting the below error:

Error from server: map: map[resources:[map[limits:[map[cpu:4000m memory:16Gi]]] map[requests:[map[cpu:3000m memory:13Gi]]]]] does not contain declared merge key: name


Solution

  • It needs to know which container you want to patch in the statefulset. You indicate this by including the name of the container.

    Also, the json structure of your resources field is incorrect. See the example below for a complete working example:

    (replace ??? with the name of the container you want patched)

    kubectl patch statefulset test -n test --patch '{"spec": {"template": {"spec": {"containers": [{"name": "???", "resources": {"limits": {"cpu": "4000m","memory": "16Gi"},"requests": {"cpu": "3000m","memory": "13Gi"}}}]}}}}'