Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oc get pods - Command to just print pod names

I want to get a list of just the pod names and the Result should not include the status, number of instances etc.

I am using the command

oc get pods

It prints

Pod1-qawer            Running           1/1           2d
Pod2g-bvch            Running           1/1           3h

Expected result

Pod1-qawer
Pod2g-bvch

How do i avoid the extra details from getting printed

like image 939
lr-pal Avatar asked Aug 28 '19 21:08

lr-pal


2 Answers

Use the oc get <object> -o name syntax, here (for pods):

oc get pods -o name

but it also applies to dc, svc, route, template, ..

Sample output: pod/m0001-v5-tst-1-b5xfs pod/m0001-v5-tst-1-mv5zl

note that these object prefixes (here: pod/) are perfectly acceptable for all oc client tools commands, so no need to strip the prefixes, they can stay and be processed further, e.g. thus:

$ oc describe $(oc get pods -o name | grep m0001-v5) | grep TAG CONTAINER_TAG: 20200430 CONTAINER_TAG: 20200430

Notice we do not use pods as usual (i.e. oc describe not oc describe pods) to avoid duplication.

Another example:

$ oc delete $(oc get dc,svc,route,is -o name)
service "nginx" deleted
route.route.openshift.io "nginx" deleted
imagestream.image.openshift.io "nginx" deleted
like image 180
mirekphd Avatar answered Nov 15 '22 02:11

mirekphd


You can omit the headers with --no-headers and you can use -o custom-columns= to customize the output.

oc get pods -o custom-columns=POD:.metadata.name --no-headers

Example output

$ oc get pods -o custom-columns=POD:.metadata.name --no-headers
goapp-75d9b6bfbf-b5fdh
httpd-58c5c54fff-b97h8
app-proxy-6c8dfb4899-8vdkb
app-64d5985fdb-xjp58
httpd-dd5976fc-rsnhz
like image 39
Jonas Avatar answered Nov 15 '22 04:11

Jonas