如何在Kubernetes容器中远程创建文件?

uajslkp6  于 2022-12-11  发布在  Kubernetes
关注(0)|答案(1)|浏览(160)

我有一个名为nginx的pod,其中有两个名为nginxbusybox的容器。要在busybox容器中创建文件,我必须执行以下操作:

$ kubectl exec -it nginx -c busybox -- bin/sh
# echo sometext > /temp/testfile
# exit

我想把它简化成一行程序,所以我试着:

$ kubectl exec -it nginx -c busybox -- echo sometext > /temp/testfile

但是,它给我带来了这样的错误:

bash: /temp/testfile: No such file or directory

echo sometext > /temp/testfile放在双引号中会产生以下错误:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "echo sometext > /temp/testfile": stat echo sometext > /temp/testfile: no such file or directory: unknown

为什么不行?有没有办法做这样的一句话?

1l5u6lss

1l5u6lss1#

试试这个

kubectl exec -it nginx -c busybox -- sh -c "echo sometext > /temp/testfile"

相关问题