尝试在kubernetes上的生命周期标签下使用命令时出现错误
即时通讯成功运行kubernetes,gcloud和postgres,但我想做一些修改后,启动后,即时通讯尝试移动一些文件,所以我尝试了这3个选项
1
image: paunin/postgresql-cluster-pgsql lifecycle: postStart: exec: command: [/bin/cp /var/lib/postgres/data /tmpdatavolume/]
2
image: paunin/postgresql-cluster-pgsql lifecycle: postStart: exec: command: - "cp" - "/var/lib/postgres/data" - "/tmpdatavolume/"
3
image: paunin/postgresql-cluster-pgsql lifecycle: postStart: exec: command: ["/bin/cp "] args: ["/var/lib/postgres/data","/tmpdatavolume/"]
在选项1和2,即时获取相同的错误(从kubectl获取事件 )
Killing container with docker id f436e40f5df2: PostStart handler: Error ex ecuting in Docker Container: -1
并在选项3它不会让我上传yaml文件给我这个错误
error validating "postgres-master.yaml": error validating data: found invalid field args for v1.ExecAction; if you choose to ignore these errors, turn validation off with --validate=false
任何帮助,将不胜感激! 谢谢。 PD:我刚刚粘贴了我的YAML文件的一部分,因为我没有得到任何错误,因为我添加了这些新行
这是关于生命周期钩子的文档,您可能会觉得有用。
你的选项1不会工作,应该给你看到的错误,应该是["/bin/cp","/var/lib/postgres/data","/tmpdatavolume/"]
。 选项2也是指定它的正确方法。 您可以将kubectl exec
放入您的pod中,然后键入这些命令以查看生成哪些错误消息? 做一些像kubectl exec <pod-name> -i -t -- bash -il
选项3中显示的错误消息意味着您没有将有效的configuration传递给API服务器。 要了解API定义,请参阅v1.Lifecycle,并在点击几下鼠标后,您会发现args
在lifecycle.postStart.exec
下无效。
或者,您可以使用kubectl explain
来find这些API定义,例如kubectl explain pods.spec.containers.lifecycle.postStart.exec
在这种情况下kubectl explain pods.spec.containers.lifecycle.postStart.exec
。