[英]oc patch replace image name error " json: cannot unmarshal object into Go value of type jsonpatch.Patch"
[英]How to fix json unmarshal error while executing kubectl patch command?
在學習以下教程時: https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/我遇到了錯誤。 以下命令失敗:
kubectl patch sts web -p '{"spec":{"replicas":3}}'
Error from server (BadRequest): json: cannot unmarshal string into Go value of type map[string]interface {}
我該如何解決?
這是 pod 上的容器鏡像:k8s.gcr.io/nginx-slim:0.8
我在 Windows 7 Pro 和標准 cmd shell 上使用 minikube。
kubectl 版本
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0",
GitCommit:"2bd9643cee5b3b3a5ecbd3af
9d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z",
GoVersion:"go1.12.9", Compiler:"gc"
Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0",
GitCommit:"2bd9643cee5b3b3a5ecbd3af
9d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z",
GoVersion:"go1.12.9", Compiler:"gc"
Platform:"linux/amd64"}
嘗試用雙引號括起來,然后 escaping 里面的雙引號:
kubectl patch sts web -p "{\"spec\":{\"replicas\":3}}"
由於您要執行scale ,因此您應該使用kubectl
提供的命令:
kubectl scale statefulset web --replicas=3
除了接受的答案之外,如果您嘗試從文件中應用補丁,您也可能會收到此錯誤。 在這種情況下,您可以按如下方式對文件進行分類:
kubectl patch deployment/<deployment-name> -p "$(cat <patch-file-name>.yaml)" --namespace <namespace name>
請參閱此處了解更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.