【问题标题】:kubectl exec: Permission deniedkubectl exec:权限被拒绝
【发布时间】:2019-01-01 13:44:08
【问题描述】:

尝试将一些新条目附加到 pod 中的 /etc/hosts,但失败:

$ ips=$(cat ips.txt); kubectl exec -u root myspark-master-5d6656bd84-5zf2h echo "$ips" >> /etc/hosts
-sh: /etc/hosts: Permission denied

如何解决这个问题?

谢谢

更新

$ ips=$(cat ips.txt); kubectl exec myspark-worker-5976b685b4-8bcbl -- sh -c "echo $ips >> /etc/hosts"
sh: 2: 10.233.88.5: not found
sh: 3: 10.233.96.2: not found
sh: 4: 10.233.86.5: not found
10.233.88.4 myspark-master-5d6656bd84-dxhxc
command terminated with exit code 127

【问题讨论】:

    标签: kubernetes kubectl


    【解决方案1】:

    我认为您的意思是写入容器内的文件,但 bash 正在您的工作站上解析该文件并尝试在本地应用重定向。请改用kubectl exec ... -- sh -c “...”

    【讨论】:

    • 我试过$ ips=$(cat ips.txt); kubectl exec myspark-worker-5976b685b4-8bcbl -- sh -c "echo $ips >> /etc/hosts" sh: 2: 10.233.88.5: not found sh: 3: 10.233.96.2: not found sh: 4: 10.233.86.5: not found 10.233.88.4 myspark-master-5d6656bd84-dxhxc command terminated with exit code 127
    • 如另一个答案中所述,请记住这是 very 字面意思。文件中的换行符表示命令中的换行符。
    【解决方案2】:

    确实存在解析问题,因为$ips 包含新行。

    试试

    $ ips=$(cat ips.txt); kubectl exec myspark-worker-5976b685b4-8bcbl -- sh -c "echo \"$ips\" >> /etc/hosts"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      • 2022-08-08
      • 2023-01-26
      • 2022-12-21
      • 2015-05-11
      • 2017-08-02
      相关资源
      最近更新 更多