<p>To exec into a container in a pod, I use the following two commands (note the <code>template</code> flag in the first command trims the output to print just the name of the pods):</p>
<pre><code>$ kubectl get pods --template '{{range .items}}{{.metadata.name}}{{&quot;\n&quot;}}{{end}}'
app-api-6421cdf4fd-x9tbk
app-worker-432f86f54-fknxw
app-frontend-87dd65d49c-6b4mn
app-rabbit-413632c874-s2ptw

$ kubectl exec -it app-api-6421cdf4fd-x9tbk -- bash
</code></pre>
<p>It would be nice to exec into the container without having to discover the random guid at the end of the pod name every single time. How can I do this?</p>

Johnny Metz
<p>You can exec into a pod using the deployment <br>
You can use the following command:</p>
<pre><code>kubectl exec -it deploy/&lt;deployment-name&gt; -- bash
</code></pre>
