<p>I often run tasks like:</p>

<ul>
<li>Read the log of the service  <code>X</code> 
or</li>
<li>Attach a shell inside the service <code>Y</code></li>
</ul>

<p>I always use something in my history like:</p>

<pre><code>kubectl logs `kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep &lt;partial_name&gt;`
</code></pre>

<p>or</p>

<pre><code>kubectl exec -it `kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep &lt;partial_name&gt;` bash
</code></pre>

<p>Do you know if <code>kubectl</code> has already something in place for this? Or should I create my own set of aliases?</p>

ProvoPropoli
<p>added to my <code>.zshconfig</code></p>
<pre><code>sshpod () {
  kubectl exec --stdin --tty `kubectl get pods --no-headers -o custom-columns=&quot;:metadata.name&quot; | grep ${1} | head -n 1` -- /bin/bash
}
</code></pre>
<p>usage</p>
<p><code>sshpod podname</code></p>
<p>this</p>
<ol>
<li>finds all pods</li>
<li>greps needed name</li>
<li>picks the first</li>
<li>sshs into the pod</li>
</ol>
