OpenShift - Display a pods YAML or JSON

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

A node contains one or more pods, and each pod contains one or more containers.


The oc get pod command with one of the following options can be used to display the pods JSON or YAML.

  • -o json or --output json
  • -o yaml or --output yaml
oc get pod foo-67b6d87679-vmzmz -o yaml


Something like this should be returned.

apiVersion: v1
kind: Pod
  annotations: |-
          "name": "",
          "interface": "eth0",
          "ips": [
          "default": true,
          "dns": {}
      }] restricted
  creationTimestamp: "2022-02-02T17:28:53Z"
  generateName: foo-67b6d87679-


Or like this, using JSON.

~]$ oc get pod php-73-rhel7-cf8fc698-zfjc5 --output json
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
        "creationTimestamp": "2022-06-24T01:39:22Z",
        "generateName": "php-73-rhel7-cf8fc698-",
        "labels": {
            "deployment": "php-73-rhel7",
            "pod-template-hash": "cf8fc698"


jsonpath can be used to print the value of a specific JSON key.

~]$ oc get pod php-73-rhel7-cf8fc698-zfjc5 --output jsonpath={.apiVersion}


And like this, iterating through keys and arrays.

~]$ oc get pod php-73-rhel7-cf8fc698-zfjc5 --output jsonpath={.spec.containers[0].image}


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

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


Web design by yours truely - me, myself, and I   |   |