0

Is it possibile to extract all the childrens of a parent node without respective data? For example, using jsonpath, I'd want list all options available under "spec", like below

containers 
restartPolicy 
dnsPolicy
{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "nginx",
        "creationTimestamp": null,
        "labels": {
            "run": "nginx"
        }
    },
    "spec": {
        "containers": [
            {
                "name": "nginx",
                "image": "nginx",
                "resources": {}
            }
        ],
        "restartPolicy": "Always",
        "dnsPolicy": "ClusterFirst"
    },
    "status": {}
}

igpix
  • 1
  • 3

1 Answers1

0

you could use jq for parsing JSON output of kubectl commands. The below command will give keys of that level as you want.

kubectl get po ... -o json | jq '.spec | keys '
Emre Odabaş
  • 409
  • 3
  • 6
  • Thanks it works! Why the result is different if I search inside spec.containers? Like `kubectl run pod --image=nginx --dry-run=client -o json | jq '.spec.containers | keys '` – igpix Jan 21 '21 at 13:04