<p>Small question regarding Kubernetes, and the kubectl command please.</p>
<p>Currently, I perform three separate actions:</p>
<p>action 1:
<code>kubectl -n=mynamespace apply -f /path/to/manifest.yml</code></p>
<p>Based on the successful creation, when I see the <code>created</code> I perform action 2, in order to retrieve the pod</p>
<p><code>kubectl -n=mynamespace get all</code></p>
<p>This step is purely a manual, time consuming and error prone step.
I have to look at the terminal with eyes, selecting the correct pod name. Just to copy paste manually, the latest pod created from step 1.</p>
<p>I will be looking with my eye for something like this, and manually copy paste:
<code>pod/my-pod-6bd84ccb9f-6kjwj</code></p>
<p>Once I get the pod, I go with action 3, which is to <strong>exec</strong> inside the pod, with the copy paste from step 2:</p>
<p><code>kubectl -n=mynamespace exec -it pod/my-pod-6bd84ccb9f-6kjwj -- bash</code></p>
<p>I feel like this is not the correct solution, and because of my ignorance, I am doing unnecessary steps.</p>
<p>May I ask if there is a smarter way to simply just create the pod, then to be able to directly exec inside this pod?</p>
<p>Some kind of command which will allow this.</p>
<p><code>kubectl -n=mynamespace exec -it {into the pod I just created from kubectl apply -f file.yml} -- bash</code></p>
<p>Thank you.</p>

<p>Not really. There is <code>kubectl run -i</code> but I don't think that's what you're looking for? Really the answer is &quot;don't&quot;. <code>kubectl exec</code> is intended only for very rare debugging use and if you're doing it enough to be annoyed, something is probably very very wrong with your workflow. What do you think you need it?</p>
