如何在执行kubectl patch命令时修复json解组错误?

遵循以下教程时: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",BuildDate:"2019-09-18T14:27:17Z",Compiler:"gc"
Platform:"linux/amd64"}
heshenzhi0622 回答:如何在执行kubectl patch命令时修复json解组错误?

尝试用双引号将其引起来,然后转义内部的双引号:

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>

有关更多信息,请参阅 here

本文链接:https://www.f2er.com/3135842.html

大家都在问