<p>I am currently working on a <code>bash</code> script to reduce the time it takes for me to build the <code>db</code> for a project. 
Currently I have several databases running in the same namespace and I want to extract only the specific pod name.</p>

<p>I run <code>kubectl get pods</code></p>

<pre><code>NAME                        READY   STATUS    RESTARTS   AGE
elastic                     1/1     Running   0          37h
mysql                       1/1     Running   0          37h
</code></pre>

<p>Now I want to save one of the pod names.</p>

<p>I'm currently running this <code>foo=$(kubectl get pods | grep -e "mysql")</code>
and it returns <code>mysql                  1/1     Running   0          37h</code> which is the expected results of the command. Now I just want to be able to extract the pod name as that variable so that I can pass it on at a later time.</p>

<p><code>kubectl</code> already allows you to extract only the names:</p>
<pre><code>kubectl get pods -o=jsonpath='{range .items..metadata}{.name}{&quot;\n&quot;}{end}' | fgrep mysql
</code></pre>
