<p>My pods have a dynamically generated ID appended to their names like i.e. <code>my-app-name-7b587cd75b-dscsr</code> which is different on every deployment (next time it could be <code>my-app-name-xcgv83bfsd-4kjsf</code>).</p>

<p>This makes using some commands really cumbersome, because every time I need to see the logs I have to list all pods first and copy-paste the changed name to the <code>logs</code> command: <code>kubectl -n [namespace] logs my-app-name-7b587cd75b-dscsr</code>.</p>

<p>Is there a way I can skip using the pod name or part of the name and do something like <code>kubectl -n [namespace] logs my-pod-name-~</code> or <code>kubectl -n [namespace] logs service/my-pod-name</code> like in <code>port-forward</code> command?</p>

<p>I tried to inject <code>grep</code> inside the <code>logs</code> command to obtain the pod name and run <code>logs</code> in a single command, but Cmder on Windows, as great as it is, doesn't seem to support <code>$()</code>: <code>kubectl -n [namespace] logs $(kubectl -n my-app-name get pod | grep my-app-name | sed 's/ .*//')</code></p>

van_folmert
<p>Rather than using <strong>POD/$POD_NAME,</strong> you can use <strong>Deployment/$DEPLOYMENT_NAME</strong> to fetch the logs of pods</p>
<p><code>kubectl logs deployment/$DEPLOY_NAME</code></p>
<pre><code>
  # Return snapshot logs from container nginx-1 of a deployment named nginx
  kubectl logs deployment/nginx -c nginx-1

</code></pre>
<p><code>kubectl logs --help</code> will provide more info</p>
