<p>I am using prometheus(v2.16.0) to scrape the metrics data,now I want to login prometheus pod to check the config file path:</p>

<pre><code>    ~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/kubernetes/cluster/addons/prometheus ⌚ 20:29:57
$ kubectl exec -it prometheus-0 -n kube-system /bin/bash

Defaulting container name to prometheus-server-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n kube-system' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown
command terminated with exit code 126

~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/kubernetes/cluster/addons/prometheus ⌚ 20:30:10
$ kubectl exec -it prometheus-0 -n kube-system /bin/ash

Defaulting container name to prometheus-server-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n kube-system' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/ash\": stat /bin/ash: no such file or directory": unknown
command terminated with exit code 126

~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/kubernetes/cluster/addons/prometheus ⌚ 20:31:30
$ kubectl exec -it prometheus-0 -n kube-system /bash

Defaulting container name to prometheus-server-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n kube-system' to see all of the containers in this pod.
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bash\": stat /bash: no such file or directory": unknown
command terminated with exit code 126
</code></pre>

<p>obviously I could not login into the prometheus pod, and I am try another way to login into using Web UI:</p>

<p><a href="https://i.stack.imgur.com/pY35H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pY35H.png" alt="enter image description here"></a></p>

<p>is it possible to login pod like this? Why I could not login prometheus pod? </p>

Dolphin
<p>As it says in the output: </p>

<pre><code>Defaulting container name to prometheus-server-configmap-reload.
</code></pre>

<p>This means that in the pod there are multiple containers and it automatically picks the <code>prometheus-server-configmap-reload</code>. Which is probably not the container we want to access.</p>

<hr>

<p>So the correct way to access prometheus bash command line:</p>

<ol>
<li>List the containers in the pod:</li>
</ol>

<pre><code>kubectl get pods prometheus-0 -n kube-system -o jsonpath='{.spec.containers[*].name}*
</code></pre>

<ol start="2">
<li>Exec into the right container from the list above using:</li>
</ol>

<pre><code>kubectl exec --namespace &lt;namespace&gt; -it &lt;pod_name&gt; -c &lt;container&gt; /bin/ash
</code></pre>

<p>In some cases there needs to be double slash before the command as well:</p>

<pre><code>kubectl exec -it -n prometheus-0 -c prometheus //bin/bash
</code></pre>

<p>You can also try <code>/bin/sh</code> or <code>//bin/sh</code> if bash is not available in the container image.</p>

<p>Hope it helps.</p>
