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

Updated:   |  OpenShift articles

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 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 replicas 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/replicasets"

 

If the items array contains key value pairs, this means the namespace contains one or more pods. Notice in this example that the deployment has 3 replicas.

{
  "kind": "ReplicaSetList",
  "apiVersion": "apps/v1",
  "metadata": {
    "selfLink": "/apis/apps/v1/namespaces/foo/pods",
    "resourceVersion": "92368763"
  },
  "items": [
    {
      "metadata": {
        "name": "helloworld-3-2-b89cd49c8-rvg77",
        "annotations": {
          "deployment.kubernetes.io/desired-replicas": "3",
          "deployment.kubernetes.io/max-replicas": "4",
          "deployment.kubernetes.io/revision": "5"
        },
      "spec": {
        "replicas": 3,
        "selector": {
          "matchLabels": {
            "app": "helloworld"
          }
        }
      }
    }
  ]
}

 




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