kubectl exec 向pod的文件中增加内容


时间:2021/07/01

事件:测试在写脚本时需要向POD的文件中增加内容\

问题:执行 kubectl exec -it podname -n namespace -- echo "hello world" >> /etc/profile

没有写到POD的/etc/profile 文件,写入到了本地的/etc/profile文件

在测试无法解决的时候需要找到我

解决:

模拟问题:

创建POD

kubectl exec -it podname -n namespace -- echo "hello world" >> /etc/profile

模拟写入

kubectl exec -it nginx -n default -- bash `echo "hello world" >> /etc/profile`

裂开

尝试

kubectl exec -it nginx -n default -- bash -c "echo "hello world" >> /etc/profile"
hello

裂开

再尝试

kubectl exec -it nginx -n default -- bash -c "echo hello world >> /etc/profile"

问题解决

反思

如果用-c 那么bash 会从第一个非选项参数后面的字符串中读取命令,如果字符串有多个空格,第一个空格前面的字符串是要执行的命令,也就是$0, 后面的是参数,即$1, $2....


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM