<p>I'd like to get the list of kubernetes pods for a service that are "Running" and fully "Ready".</p>

<p>And by fully ready, I mean shows a full "READY" count in k9s, so if there are 4 conditions for the pod to run, I see "READY" with "4/4" listed in k9s.</p>

<p>How can I do this?</p>

Brad Parks
<p>For a particular service, <code>my-service</code>, this only shows pods that are fully ready</p>

<pre><code>$ kubectl get pods --selector=app=my-service -o json  | select_ready_pods.py
</code></pre>

<p>Similar idea for all pods</p>

<pre><code>$ kubectl get pods --all-namespaces -o json  | select_ready_pods.py
</code></pre>

<p>List pods that are NOT ready</p>

<pre><code>$ kubectl get pods --selector=app=my-service -o json  | select_ready_pods.py --not_ready
</code></pre>

<h2>select_ready_pods.py</h2>

<pre><code>#!/usr/bin/env python

import sys
import json

try:
    a = json.load(sys.stdin)
except:
    print("The data from stdin doesnt appear to be valid json. Fix this!")
    sys.exit(1)


def main(args):
    for i in a['items']:
        length = len(i['status']['conditions'])
        count = 0
        for j in i['status']['conditions']:
            if (j['status'] == "True"):
                count=count+1

        if (args.not_ready):
            if (count != length):
                print(i['metadata']['name'])
        else:
            if (count == length):
                print(i['metadata']['name'])

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--not_ready", help="show pods that are NOT ready", action="store_true")
args = parser.parse_args()

main(args)
</code></pre>
