Openshift/kubernetes: field selectors
Sometimes, I just want to see the pods where status=failed or status=running and that's where --field-selector
comes in handy.
--field-selector='': Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.
$ oc get pods --all-namespaces --field-selector=status.phase=Failed
$ oc get pods --all-namespaces --field-selector=status.phase=Running
$ oc get pods --all-namespaces --field-selector=status.phase!=Running
So, if you just want running pods in all namespaces, you could something like:
$ oc get pods --all-namespaces --field-selector=status.phase=Running
NAMESPACE NAME READY STATUS RESTARTS AGE
default docker-registry-1-xj6tx 1/1 Running 3 97d
default nfs-client-provisioner-5b4bfff58c-bz76z 1/1 Running 1 1d
default registry-console-4-ql6np 1/1 Running 2 61d
default router-1-vg9rf 1/1 Running 2 81d
Or if you want to get all failed pods:
$ oc get pods --all-namespaces --field-selector=status.phase=Failed
NAMESPACE NAME READY STATUS RESTARTS AGE
cluster-management cronjob-prune-images-1535241600-4sq9z 0/1 DeadlineExceeded 0 4d
cluster-management cronjob-prune-resources-builds-1535241600-4zxrq 0/1 DeadlineExceeded 0 4d
cluster-management cronjob-prune-resources-deployments-1535241600-55s8b 0/1 DeadlineExceeded 0 4d
logging logging-es-data-master-8u8oilnz-7-2fr7j 0/2 Evicted 0 45d
and if you want to delete them, then you could do something like:
$ oc delete $(oc get pods --field-selector=status.phase=Failed -o name -n cluster-management) -n cluster-management
Comments:
For comments, please visit https://plus.google.com/u/0/+JefferyBagirimvano/posts/UPBWhXcDtPo