<p>Try to append some new entries to /etc/hosts in pods, but failed:</p>

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

<p>How to fix this?</p>

<p>Thanks</p>

<p><strong>UPDATE</strong></p>

<pre><code>$ ips=$(cat ips.txt); kubectl exec myspark-worker-5976b685b4-8bcbl -- sh -c "echo $ips &gt;&gt; /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
</code></pre>

BAE
<p>I think you mean to write to the file inside the container, but bash is parsing that on your workstation and try to apply the redirect locally. Use <code>kubectl exec ... -- sh -c “...”</code> instead. </p>
