我正在尝试修补 kubernetes 部署对象的 liveness 和 readiness 探针参数。下面是我的patch.yml
。
---
spec:
template:
spec:
containers:
-
livenessProbe:
initialDelaySeconds: 280
name: notification-service
readinessProbe:
initialDelaySeconds: 220
要求:
kubectl -n my-namespace --kubeconfig=my_config --context=dev patch deployment notification-service --patch "$(cat patch.yml)"
回复:
kubectl : error: unable to parse "spec: template: spec: containers: - name: notification-service
readinessProbe: initialDelaySeconds: 220 livenessProbe: initialDelaySeconds: 280": yaml: mapping values are not allowed in this
context
At line:1 char:1
+ kubectl -n my-namespace --kubeconfig=my_config --context=dev patch ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (error: unable t...in this context:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
编辑:下面是kubectl version
命令的输出。
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e
9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"wind
ows/386"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698
aa92f0b1", GitTreeState:"clean", BuildDate:"2019-02-28T13:30:26Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"lin
ux/amd64"}
这是引发此错误的行。为了验证它,我尝试创建一个示例 go 程序。下面是代码片段。令我惊讶的是,下面的代码能够处理 yaml 文件。
package main
import (
"fmt"
"io/ioutil"
//"sigs.k8s.io/yaml" // Part of latest master k8s master vendor folder
yaml2 "github.com/ghodss/yaml" // Part of release 1.10 k8s vendor folder
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main(){
dat, err := ioutil.ReadFile("D:\\EclipseIDEJavaEEDevelopers\\Workspace\\patch.yaml")
check(err)
patch:=string(dat)
patchBytes, err1 := yaml2.YAMLToJSON([]byte(patch))
if err != nil {
fmt.Errorf("unable to parse %q: %v", dat, err1)
}else{
fmt.Println("json conversion completed ",string(patchBytes))
}
}
输出:
json conversion completed {"spec":{"template":{"spec":{"containers":[{"livenessProbe":{"initialDelaySeconds":280},"name":"notification-service","readinessProbe":{"initialDelaySeconds":220}}]}}}}
问题在于powershell
命令替换周围的双引号。如果我们在 powershell 中在命令替换周围添加双引号,它会从 yml 中删除新行,因此 kubectl 无法将其转换为 json。
在 bash 中同样有效。因为,我使用的是 powershell,它对我不起作用。正确的命令如下。
kubectl -n my-namespace --kubeconfig=my_config --context=dev patch deployment notification-service --patch $(cat patch.yml)
注意: yml 仍然存在一些问题。所以当我说它有效时,我的意思是当前的问题已经解决。从 kubernetes 的角度来看,yml 有很多问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句