Bootstrap FreeKB - OpenShift - List pods using REST API
OpenShift - List pods using REST API

Updated:   |  OpenShift articles

This assumes you have used the REST API to obtain an OAuth bearer token. Let's say the bearer token is sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U.

Here is how you would list the pods in the "foo" namespace using the curl REST API. The oc config view or oc get apiserver commands can be used to display the API Server URL (api.openshift.example.com in this example).

curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/api/v1/namespaces/foo/pods"

 

If something like this is returned, this means that there are no pods in the "foo" namespace.

{
  "kind": "PodList",
  "apiVersion": "v1",
  "metadata": {
    "selfLink": "/api/v1/namespaces/foo/pods",
    "resourceVersion": "92373341"
  },
  "items": []
}

 

On the other hand, if the items array contains key value pairs, this means the namespace contains one or more pods.

{
  "kind": "PodList",
  "apiVersion": "v1",
  "metadata": {
    "selfLink": "/api/v1/namespaces/foo/pods",
    "resourceVersion": "92368763"
  },
  "items": [
    {
      "metadata": {
        "name": "helloworld-0.0.5-snapshot-master-3-2-b89cd49c8-rvg77",
        "generateName": "helloworld-0.0.5-snapshot-master-3-2-b89cd49c8-",
        "namespace": "foo",
        "selfLink": "/api/v1/namespaces/foo/pods/helloworld-0.0.5-snapshot-master-3-2-b89cd49c8-rvg77"

 

Or if you know the name of the pod, you can limit the output to a single pod.

curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/api/v1/namespaces/foo/pods/example-pod"

 

If something like this is returned, this means that there are no pod named "example-pod" in the "foo" namespace.

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "pods \"example-pod\" not found",
  "reason": "NotFound",
  "details": {
    "name": "example-pod",
    "kind": "pods"
  },
  "code": 404
}



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 198e51 in the box below so that we can be sure you are a human.