<p>I deployed istio/bookinfo on kubernetes, and I want to install stress on the microservice container to inject fault. However, When I use</p>
<pre><code>kubectl exec -it reviews-v1-f55d74d54-kpxr2 -c reviews --username=root -- /bin/bash
</code></pre>
<p>to log in the container, it show that the user is still default. and the command 'apt-get' got</p>
<pre><code>default@reviews-v2-6f4995984d-4752v:/$ apt-get update
Reading package lists... Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
</code></pre>
<p>I tried to use 'su root' but I don't know the answer.
I searched some answer say that I can use 'docker exec', it works but it is not convenient, so I want to know how to log in the container by use the command kubectl exec.</p>

gxxxh
<p>This is not supported.</p>
<p>Source code suggests it's a TODO feature: <a href="https://github.com/kubernetes/kubectl/blob/a0af655b7abaf06983c99ad5a4dc8f02ae5eb3e5/pkg/cmd/exec/exec.go#L100" rel="noreferrer">kubernetes/kubectl/pkg/cmd/exec/exec.go</a></p>
<p>The <code>--username</code> flag explained by kubectl:</p>
<pre><code>➜  ~ kubectl options  | grep user    
  --user='': The name of the kubeconfig user to use
  --username='': Username for basic authentication to the API server
</code></pre>
<p>As you probably see, none of the user flags can change user/UID for exec.</p>
<p>All flags supported by exec command:</p>
<pre><code>➜  ~ kubectl exec --help
[...]

Options:
  -c, --container='': Container name. If omitted, the first container in the pod will be chosen
  -f, --filename=[]: to use to exec into the resource
      --pod-running-timeout=1m0s: The length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one
pod is running
  -i, --stdin=false: Pass stdin to the container
  -t, --tty=false: Stdin is a TTY
</code></pre>
<p>Additionally, apt-get update is best to be run at build time, not at a run time.</p>
<p>It is a good practise to keep your containers immutable. For testing purpouses you should stick with docker exec because ther is no other known alternative.</p>
<p>Also, If you have a specific problem to solve, explain the problem, not the solution. <a href="https://xyproblem.info/" rel="noreferrer">xyproblem</a></p>
