12

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

Jonas
  • 121,568
  • 97
  • 310
  • 388
lr-pal
  • 339
  • 2
  • 6
  • 20
  • 2
    Have you tried `oc get pods -o name`? Run `oc get --help` for help strings on all the options. – Graham Dumpleton Aug 28 '19 at 22:11
  • 1
    Thanks, it worked. But it adds a pod/ prefix before the pod names. Is there a way to suppress that too? – lr-pal Aug 29 '19 at 02:16
  • 2
    Use `oc get pod -o template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'`. See https://cookbook.openshift.org/working-with-resource-objects/how-can-i-selectively-display-attributes-of-a-resource.html – Graham Dumpleton Aug 29 '19 at 04:37

4 Answers4

22

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
Jonas
  • 121,568
  • 97
  • 310
  • 388
  • In my case I needed the name of running pods and it had to be filtered by a label. To see the available labels: `--show-labels=true`. Filter for label: `-l label=value`. Only running pods: `--show-all=false` – pma Jul 02 '20 at 06:50
  • hi i've accidentialy downvoted your answer ... Can you make a edit so that I can upvote it – Kraego Sep 07 '21 at 06:38
7

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
mirekphd
  • 4,799
  • 3
  • 38
  • 59
0

oc get po --no-headers | awk '{print $1}'

Maximillian Laumeister
  • 19,884
  • 8
  • 59
  • 78
0

try:

oc get pods |awk -F" " 'print {$0}'