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

Updated:   |  OpenShift articles

A deployment is used to manage the pods that are created to run an application. The deployment ensures that the desired number of pod replicas are running and can handle updates to the application by rolling out new versions of the pods. The deployment creates and manages a replica set, which in turn manages the pods.

flowchart TB subgraph Project["OpenShift Project/Namespace"] Deployment[Deployment] Replica_Set[Replica Set] subgraph Pods["Pod Replicas"] Pod1[Pod 1
Container] Pod2[Pod 2
Container] Pod3[Pod 3
Container] end end Deployment -->|Creates/Manages| Replica_Set Replica_Set -->|Manages| Pod1 Replica_Set -->|Manages| Pod2 Replica_Set -->|Manages| Pod3 style Deployment fill:#90CAF9 style Replica_Set fill:#FFE082 style Pods fill:#FFCCBC

It is also noteworthy that a route provides a URL that can be used to access the application from outside the OpenShift cluster. For example, if the route is configured to use the hostname myapp.mydomain.com, then users can access the application by navigating to http://myapp.mydomain.com. The route will forward the request to the service, which will then forward the request to one of the pods that are running the application.

flowchart LR subgraph Project["OpenShift Project/Namespace"] subgraph Pods["Pod Replicas"] Pod1[Pod 1
Container] Pod2[Pod 2
Container] Pod3[Pod 3
Container] end SVC[Service] Route[Route] end USER[External User] --> Route --> SVC SVC --> Pod1 SVC --> Pod2 SVC --> Pod3 style SVC fill:#A5D6A7 style Pods fill:#FFCCBC style USER fill:#CE93D8

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 deployments in my-project using curl.

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/my-project/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/my-project/deployments",
    "resourceVersion": "708878925"
  },
  "items": [
    {
      "metadata": {
        "name": "my-deployment",
        "namespace": "my-project",
        "selfLink": "/apis/apps/v1/namespaces/my-project/deployments/my-deployment",
        "uid": "7709e73e-3936-467c-86d6-5af3b01ca106",
        "resourceVersion": "696422824",
        "generation": 1,
        "creationTimestamp": "2021-12-17T18:55:58Z"
      }
    }
   ]
  }
}

 

You can list a single deployment by including the name of the deployment.

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/my-project/deployments/my-deployment"

 




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