Rest Query to list all containers in all namespace in Kubernetes

10/18/2018

I know there is kubectl command to list containers in all the namespaces:

kubectl get pods --all-namespaces -o jsonpath={.items[*].spec.containers[*].name}

is there a way to get all the containers in all namespaces using rest query?

-- sheikh sabeer
kubernetes
openshift
rest

1 Answer

10/18/2018

You cant query the REST API for containers directly, since the smallest unit you can manage is a Pod, as is the same in your kubectl example.

You could however query all Pods and filter using a tool like jq. So obviously, replacing your $TOKEN and $CLUSTER as appropriate, the following should work:

curl -XGET -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" https://$CLUSTER:8443/api/v1/pods?limit=500 | jq '.items[] .spec .containers[] .name'

Not sure how the above has any benefit over using the cli though. On a side note, if your using the oc tool, set the --loglevel=9 option and you will be able to see what request is being sent to the server.

-- PhilipGough
Source: StackOverflow