Bootstrap FreeKB - OpenShift - custom-columns option
OpenShift - custom-columns option

Updated:   |  OpenShift articles

A number of different oc command allow you to return output as JSON or YAML, such as the oc get pods command.

oc get pods mypod --output yaml

 

Which will typically return more output that you need.

apiVersion: v1
kind: Pod
metadata:
  annotations:
  creationTimestamp: "2021-11-23T07:27:05Z"
  generateName: helloworld-0.0.5-snapshot-master-3-2-d4fdf7c6f
spec:
  containers:
    name: helloworld
  - env:
    - name: my_secret
      valueFrom:
        secretKeyRef:
          key: foo
          name: mysecret

 

The custom-columns option can be used to limit the output. In this example, the value of the "kind" key will be returned.

~]# oc get pods mypod --output yaml --output custom-columns=":kind"
Pod

 

In this example, the value of the "apiVersion" key will be returned.

~]# oc get pods mypod --output yaml --output custom-columns=":apiVersion"
v1

 

Many of the keys in the output contain child keys. For example, specifying "spec" will return every key and value below the "spec" key, which will typically return far too much data.

Typically, below the spec key are keys such as "affinity" and "containers". Here is how you would return the name of the container.

~]# oc get pods mypod --output yaml --output custom-columns=":spec"
helloworld

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5a2221 in the box below so that we can be sure you are a human.