<p>I'm trying to create a dashboard where I can see the status of my pods within my cluster. So I have a bash script that goes something like:</p>

<pre class="lang-sh prettyprint-override"><code>SERVICE_ONE=$(kubectl get pods | grep service-one | grep -E -- 'CrashLoopBackOff|Terminating|Error|Fail')
SERVICE_TWO=$(kubectl get pods | grep service-two | grep -E -- 'CrashLoopBackOff|Terminating|Error|Fail')
SERVICE_THREE=$(kubectl get pods | grep service-three | grep -E -- 'CrashLoopBackOff|Terminating|Error|Fail')

if [ ${#SERVICE_ONE} = 0 ]
then
  SERVICE_ONE_STATUS="GOOD"
else
  SERVICE_ONE_STATUS="BAD"
</code></pre>

<p>I then post these results to a GUI. The only problem is that I have almost 20 of these <code>kubectl</code> commands, which altogether, causes the program to take over 2 minutes to run. I tried doing something like:</p>

<pre class="lang-sh prettyprint-override"><code>KUBE_OUTPUT=$(kubectl get pods)
SERVICE_ONE=$(grep service-one &lt;&lt;&lt; ${KUBE_OUTPUT} | grep -E -- 'CrashLoopBackOff|Terminating|Error|Fail')
SERVICE_TWO=$(grep service-two &lt;&lt;&lt; ${KUBE_OUTPUT} | grep -E -- 'CrashLoopBackOff|Terminating|Error|Fail')
SERVICE_THREE=$(grep service-three &lt;&lt;&lt; ${KUBE_OUTPUT} | grep -E -- 'CrashLoopBackOff|Terminating|Error|Fail')
</code></pre>

<p>But this doesn't work since the kube output isn't saved in the same format as when I run it plainly on my terminal (there's spacing issues, no newlines, etc.). I was wondering if there was a better way of executing multiple <code>kubectl</code> commands at once?</p>

olivercollins-inhome
<p>since, running kubectl command every time to get the pod details will take the time.</p>
<p>i tried kubectl get pods with -o=jsonpath something like below</p>
<pre><code>$  VAR=$(kubectl get pods -o=jsonpath=&quot;{range .items[*]}{.metadata.name}{'\t'}{.status.phase}{'\n'}{end}&quot;$'\r' | grep -E -- 'CrashLoopBackOff|T
erminating|Error|Fail|Running')

</code></pre>
<p>This will filter the result with NAME and STATUS of the pod.
the output would be like</p>
<pre><code>$ IFS=' '
$ echo $VAR
my-deployment-55bc8b77dd-8plsw  Running
my-deployment-55bc8b77dd-crlbx  Running
my-deployment-55bc8b77dd-jqqx4  Running
my-deployment-55bc8b77dd-mnm5k  Running
my-deployment-55bc8b77dd-zndvs  Running
</code></pre>
<p>Now you can again filter based in the pod name</p>
<pre><code>$ SERVICE=$(echo $VAR | grep my-deployment-55bc8b77dd-8plsw)
</code></pre>
<p>the output will  be</p>
<pre><code>$ echo $SERVICE
my-deployment-55bc8b77dd-8plsw  Running
</code></pre>
<p>now split the result and display the status as you like.
If this is not what you are looking for. plz put a comment.</p>
