Hide Completed and other finished pods by default

9/24/2018

In my professional environment it is common for "completed" pods to outnumber active ones and they often clutter the output of kubectl get pods like so:

$ kubectl get pods
finished-pod-38163    0/1 Completed    2m
errored-pod-83023     0/1 Error        2m
running-pod-20899     1/1 Running      2m

I can filter them out using --show-all=false:

$ kubectl get pods --show-all=false
running-pod-20899     1/1 Running      2m

However I would prefer not to have to type out --show-all=false every time I want to see my running pods. Is it possible to configure kubectl to disable --show-all by default rather than having it enabled by default?

From kubectl get pods --help:

-a, --show-all=true: When printing, show all resources (default show all pods
                     including terminated one.)

I know I could create some shell alias kgetpo, but this would remove support for tab-completion so I'd prefer native solutions if they exist.

-- Cory Klein
kubectl
kubernetes

1 Answer

2/25/2020

You can create something like this:

kubectl get pods --field-selector=status.phase==Running
-- New User 77
Source: StackOverflow