OpenShift - List replicas 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 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

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 50c3c 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   |