如何使用pod-local环境变量在pod上执行kubectl命令?

时间:2019-10-15 12:51:02

标签: docker kubectl

我正在尝试运行需要使用特定于容器的环境变量($ JAVA_HOME)的命令,但是似乎在将命令发送到pod容器之前,该变量已在我的本地shell中展开

kubectl exec my-pod "echo ${JAVA_HOME}"

产生:

Use 'kubectl describe pod/my-pod -n default' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"echo \": executable file not found in $PATH": unknown
command terminated with exit code 126

我尝试了几种没有运气的语法(例如bash -c)。如何转义变量以便在目标容器上对其求值?

1 个答案:

答案 0 :(得分:2)

尝试一下:

John