<p>I'm using kubernetes for deploying applications, and </p>

<pre><code>kubect logs
</code></pre>

<p>for logs viewing.
Redeployments are very often, so it's bit uncomfortable - to copy <code>pod</code> name each time to paste in log command(because end of pod name dinamically changes each time), e.g. below are commands for same application, after 2 deployments</p>

<pre><code>kubectl logs -n=testns --since=1m testapp-2818008534-jx2vv
kubectl logs -n=testns --since=1m testapp-2818008534-xls93
</code></pre>

<p>So, I want to use one command, which will correctly "pick up" needed POD name each time we'r running the "<code>kubectl logs</code>".</p>

<p>But smth like</p>

<pre><code>$kubectl logs -n=testns --since=1h $(kubectl get pods --namespace=testns | grep testapp)
</code></pre>

<p>returns an error, that we are not "giving" pod name, BUT that pod exists for sure:</p>

<pre><code>error: expected 'logs (POD | TYPE/NAME) [CONTAINER_NAME]'.
POD or TYPE/NAME is a required argument for the logs command
</code></pre>

<p>So, how to correctly set this command, to use it every time we want to look at logs, without need to re-copypaste full POD name?</p>

<p>When you do:</p>

<p><code>kubectl get pods --namespace=testns | grep testapp</code></p>

<p>You get something like:</p>

<p><code>testapp-54d99599bc-g2gs4           1/1       Running   0          56m</code></p>

<p>So this won't go well with logs command as it has some additional data which can not be understood by Kubectl. What you can do is:</p>

<p><code>kubectl get pods --namespace=testns | grep testapp | cut -d' ' -f1</code></p>

<p>Which will produce only name of the POD and then your log command should work.</p>
