我有一个app/pod:带有2个容器app1service1service2。这些服务将日志写入/var/log/app1Service1.log和/var/log/aapp1Service2.log。我想从mac的cli拖尾日志。尝试如下,但没有用。

~ $ kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 "tail -f -n +1 /var/log/app1Service1.log"
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"tail -f -n +1 /var/log/app1Service1.log\": stat tail -f -n +1 /var/log/app1Service1.log: no such file or directory"

command terminated with exit code 126
~ $

下面的命令有效:
kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 ls
kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 "ls"

将参数传递给命令时看到失败。

最佳答案

添加bash -c,或者如果您的容器具有sh,则添加sh -c

kubectl exec app1-6f6749ccdd-4ktwf -c app1Service1 -- bash -c "tail -f -n +1 /var/log/app1Service1.log"

希望这会有所帮助

关于kubernetes - 如何在 'command with arguments'的容器上执行 'multi-container pod'?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53605017/

10-15 23:23