OpenShift - List deployments using REST API

An image contains the code used to create a deployment. Then, a deployment can be created from an image, which should then create a replica set (which is the number of pods that should be created), and then the pods should be created.

This assumes you have used the curl 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 deployments 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/apis/apps/v1/namespaces/foo/deployments"

 

If the items array contains key value pairs, this means the namespace contains one or more deployments.

{
  "kind": "DeploymentList",
  "apiVersion": "apps/v1",
  "metadata": {
    "selfLink": "/apis/apps/v1/namespaces/foo/deployments",
    "resourceVersion": "708878925"
  },
  "items": [
    {
      "metadata": {
        "name": "app001-5b9879db6d",
        "namespace": "foo",
        "selfLink": "/apis/apps/v1/namespaces/foo/deployments/app001-5b9879db6d",
        "uid": "7709e73e-3936-467c-86d6-5af3b01ca106",
        "resourceVersion": "696422824",
        "generation": 1,
        "creationTimestamp": "2021-12-17T18:55:58Z"
      }
    }
   ]
  }
}

 




Did you find this article helpful?

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

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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |