Bootstrap FreeKB - OpenShift - List Nodes using the REST API
OpenShift - List Nodes using the REST API

Updated:   |  OpenShift articles

I like to think of a machine as OpenShift representation of a Virtual Machine, such as an Amazon Web Services (AWS) EC2 Instance, or a VMWare Virtual Machine, and then a Node, and then the pods running on the node. Machine Configs can be used to configure the Virtual Machine Operating System, such as configuring a Linux systemd service such as sshd or chronyd or Network Manager.

 

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 Nodes 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/api/v1/nodes"

 

Or to return a specific node.

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/nodes/my-node-2xqdt"

 

Something like this should be returned.

{
  "kind": "Node",
  "apiVersion": "v1",
  "metadata": {
    "name": "my-cluster-worker-2xqdt",    
    "uid": "b3b3bef4-3ed8-4170-a4a3-5195bcdb0c9b",
    "resourceVersion": "484291831",
    "creationTimestamp": "2023-07-07T15:41:04Z",
    "labels": {
      "beta.kubernetes.io/arch": "amd64",
      "beta.kubernetes.io/os": "linux",
      "kubernetes.io/arch": "amd64",
      "kubernetes.io/hostname": "my-cluster-worker-2xqdt",
      "kubernetes.io/os": "linux",
      "node-role.kubernetes.io/compute": "",
      "node-role.kubernetes.io/worker": "",
      "node-type": "general",
      "node.openshift.io/os_id": "rhcos"
    },
    "annotations": {
      "k8s.ovn.org/remote-zone-migrated": "my-cluster-worker-2xqdt",
      "k8s.ovn.org/zone-name": "my-cluster-worker-2xqdt",
      "machine.openshift.io/machine": "openshift-machine-api/my-cluster-worker-2xqdt",
      "machineconfiguration.openshift.io/controlPlaneTopology": "HighlyAvailable",
      "machineconfiguration.openshift.io/currentConfig": "rendered-worker-0ed1cb20db859faef7f01f41079c21b2",
      "machineconfiguration.openshift.io/desiredConfig": "rendered-worker-0ed1cb20db859faef7f01f41079c21b2",
      "machineconfiguration.openshift.io/desiredDrain": "uncordon-rendered-worker-0ed1cb20db859faef7f01f41079c21b2",
      "machineconfiguration.openshift.io/lastAppliedDrain": "uncordon-rendered-worker-0ed1cb20db859faef7f01f41079c21b2",
      "machineconfiguration.openshift.io/lastObservedServerCAAnnotation": "false",
      "machineconfiguration.openshift.io/lastSyncedControllerConfigResourceVersion": "478982937",
      "machineconfiguration.openshift.io/post-config-action": "",
      "machineconfiguration.openshift.io/reason": "",
      "machineconfiguration.openshift.io/state": "Done",
      "volumes.kubernetes.io/controller-managed-attach-detach": "true"
    },
    "managedFields": [
      {
        "manager": "ancient-changes",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2023-07-07T15:41:04Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              ".": {},
              "f:machine.openshift.io/machine": {},
              "f:volumes.kubernetes.io/controller-managed-attach-detach": {}
            },
            "f:labels": {
              ".": {},
              "f:beta.kubernetes.io/arch": {},
              "f:beta.kubernetes.io/os": {},
              "f:kubernetes.io/arch": {},
              "f:kubernetes.io/hostname": {},
              "f:kubernetes.io/os": {},
              "f:node-role.kubernetes.io/worker": {},
              "f:node.openshift.io/os_id": {}
            }
          },
          "f:spec": {
            "f:providerID": {}
          }
        }
      },
      {
        "manager": "Mozilla",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2023-07-11T15:49:33Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:labels": {
              "f:node-role.kubernetes.io/compute": {},
              "f:node-type": {}
            }
          }
        }
      },
      {
        "manager": "kubectl-annotate",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2025-03-21T16:14:53Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              "f:k8s.ovn.org/hybrid-overlay-node-subnet": {},
              "f:k8s.ovn.org/node-subnets": {}
            }
          }
        }
      },
      {
        "manager": "machine-config-controller",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2025-03-21T17:05:54Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              "f:machineconfiguration.openshift.io/controlPlaneTopology": {},
              "f:machineconfiguration.openshift.io/desiredConfig": {},
              "f:machineconfiguration.openshift.io/lastAppliedDrain": {}
            }
          }
        }
      },
      {
        "manager": "my-cluster-master-2",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2025-03-21T17:06:08Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              "f:k8s.ovn.org/network-ids": {},
              "f:k8s.ovn.org/node-gateway-router-lrp-ifaddr": {},
              "f:k8s.ovn.org/node-id": {},
              "f:k8s.ovn.org/node-transit-switch-port-ifaddr": {}
            }
          }
        },
        "subresource": "status"
      },
      {
        "manager": "my-cluster-worker-2xqdt",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2025-03-21T17:06:09Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              "f:k8s.ovn.org/host-cidrs": {},
              "f:k8s.ovn.org/l3-gateway-config": {},
              "f:k8s.ovn.org/node-chassis-id": {},
              "f:k8s.ovn.org/node-mgmt-port-mac-address": {},
              "f:k8s.ovn.org/node-primary-ifaddr": {},
              "f:k8s.ovn.org/remote-zone-migrated": {},
              "f:k8s.ovn.org/zone-name": {}
            }
          }
        },
        "subresource": "status"
      },
      {
        "manager": "machine-config-daemon",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2025-03-26T03:00:33Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              "f:machineconfiguration.openshift.io/currentConfig": {},
              "f:machineconfiguration.openshift.io/desiredDrain": {},
              "f:machineconfiguration.openshift.io/lastObservedServerCAAnnotation": {},
              "f:machineconfiguration.openshift.io/lastSyncedControllerConfigResourceVersion": {},
              "f:machineconfiguration.openshift.io/post-config-action": {},
              "f:machineconfiguration.openshift.io/reason": {},
              "f:machineconfiguration.openshift.io/state": {}
            }
          }
        }
      },
      {
        "manager": "kubelet",
        "operation": "Update",
        "apiVersion": "v1",
        "time": "2025-04-01T08:56:38Z",
        "fieldsType": "FieldsV1",
        "fieldsV1": {
          "f:metadata": {
            "f:annotations": {
              "f:alpha.kubernetes.io/provided-node-ip": {},
              "f:csi.volume.kubernetes.io/nodeid": {}
            }
          },
          "f:status": {
            "f:allocatable": {
              "f:ephemeral-storage": {},
              "f:memory": {}
            },
            "f:capacity": {
              "f:memory": {}
            },
            "f:conditions": {
              "k:{\"type\":\"DiskPressure\"}": {
                "f:lastHeartbeatTime": {},
                "f:lastTransitionTime": {},
                "f:message": {},
                "f:reason": {},
                "f:status": {}
              },
              "k:{\"type\":\"MemoryPressure\"}": {
                "f:lastHeartbeatTime": {},
                "f:lastTransitionTime": {},
                "f:message": {},
                "f:reason": {},
                "f:status": {}
              },
              "k:{\"type\":\"PIDPressure\"}": {
                "f:lastHeartbeatTime": {},
                "f:lastTransitionTime": {},
                "f:message": {},
                "f:reason": {},
                "f:status": {}
              },
              "k:{\"type\":\"Ready\"}": {
                "f:lastHeartbeatTime": {},
                "f:lastTransitionTime": {},
                "f:message": {},
                "f:reason": {},
                "f:status": {}
              }
            },
            "f:images": {},
            "f:nodeInfo": {
              "f:bootID": {},
              "f:containerRuntimeVersion": {},
              "f:kernelVersion": {},
              "f:kubeProxyVersion": {},
              "f:kubeletVersion": {},
              "f:osImage": {}
            }
          }
        },
        "subresource": "status"
      }
    ]
  },
  "spec": {
    "providerID": "vsphere://423c21f0-c4f4-fa1e-c658-b7f68078f767"
  },
  "status": {
    "capacity": {
      "cpu": "4",
      "ephemeral-storage": "125293548Ki",
      "hugepages-1Gi": "0",
      "hugepages-2Mi": "0",
      "memory": "65696076Ki",
      "pods": "250"
    },
    "allocatable": {
      "cpu": "3500m",
      "ephemeral-storage": "114396791822",
      "hugepages-1Gi": "0",
      "hugepages-2Mi": "0",
      "memory": "62447948Ki",
      "pods": "250"
    },
    "conditions": [
      {
        "type": "MemoryPressure",
        "status": "False",
        "lastHeartbeatTime": "2025-04-01T08:56:38Z",
        "lastTransitionTime": "2025-03-21T16:23:49Z",
        "reason": "KubeletHasSufficientMemory",
        "message": "kubelet has sufficient memory available"
      },
      {
        "type": "DiskPressure",
        "status": "False",
        "lastHeartbeatTime": "2025-04-01T08:56:38Z",
        "lastTransitionTime": "2025-03-21T16:23:49Z",
        "reason": "KubeletHasNoDiskPressure",
        "message": "kubelet has no disk pressure"
      },
      {
        "type": "PIDPressure",
        "status": "False",
        "lastHeartbeatTime": "2025-04-01T08:56:38Z",
        "lastTransitionTime": "2025-03-21T16:23:49Z",
        "reason": "KubeletHasSufficientPID",
        "message": "kubelet has sufficient PID available"
      },
      {
        "type": "Ready",
        "status": "True",
        "lastHeartbeatTime": "2025-04-01T08:56:38Z",
        "lastTransitionTime": "2025-03-21T17:06:12Z",
        "reason": "KubeletReady",
        "message": "kubelet is posting ready status"
      }
    ],
    "addresses": [
      {
        "type": "ExternalIP",
        "address": "10.11.12.13"
      },
      {
        "type": "InternalIP",
        "address": "10.11.12.13"
      },
      {
        "type": "Hostname",
        "address": "my-cluster-worker-2xqdt"
      }
    ],
    "daemonEndpoints": {
      "kubeletEndpoint": {
        "Port": 10250
      }
    },
    "nodeInfo": {
      "machineID": "6d0af6f5671e475ab8056512fa02c54f",
      "systemUUID": "f0213c42-f4c4-1efa-c658-b7f68078f767",
      "bootID": "ae902428-7efe-442a-a12b-10e55ecf3647",
      "kernelVersion": "5.14.0-427.50.1.el9_4.x86_64",
      "osImage": "Red Hat Enterprise Linux CoreOS 416.94.202501030250-0",
      "containerRuntimeVersion": "cri-o://1.29.11-3.rhaos4.16.git16d9bd6.el9",
      "kubeletVersion": "v1.29.10+67d3387",
      "kubeProxyVersion": "v1.29.10+67d3387",
      "operatingSystem": "linux",
      "architecture": "amd64"
    },
    "images": [
      {
        "names": [
          "quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:82552f70c1292239539594b1170de68885197350dda49772375ac94797cd4b8f"
        ],
        "sizeBytes": 650329274
      }
    ]
  }
}

 




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