OpenShift - List Machines using the REST API

by
Jeremy Canfield |
Updated: February 01 2025
| 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 Machines 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/machine.openshift.io/v1beta1/namespaces/openshift-machine-api/machines"
Or to return a specific machine.
curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/apis/machine.openshift.io/v1beta1/namespaces/openshift-machine-api/machines/my-machine-2xqdt"
Something like this should be returned.
{
"apiVersion": "machine.openshift.io/v1beta1",
"kind": "Machine",
"metadata": {
"annotations": {
"machine.openshift.io/instance-state": "poweredOn"
},
"creationTimestamp": "2023-07-07T15:34:29Z",
"finalizers": [
"machine.machine.openshift.io"
],
"generateName": "my-worker-",
"generation": 2,
"labels": {
"machine.openshift.io/cluster-api-cluster": "my-cluster",
"machine.openshift.io/cluster-api-machine-role": "worker",
"machine.openshift.io/cluster-api-machine-type": "worker",
"machine.openshift.io/cluster-api-machineset": "my-cluster-worker",
"machine.openshift.io/region": "",
"machine.openshift.io/zone": ""
},
"managedFields": [
{
"apiVersion": "machine.openshift.io/v1beta1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:generateName": {},
"f:labels": {
".": {},
"f:machine.openshift.io/cluster-api-cluster": {},
"f:machine.openshift.io/cluster-api-machine-role": {},
"f:machine.openshift.io/cluster-api-machine-type": {},
"f:machine.openshift.io/cluster-api-machineset": {}
},
"f:ownerReferences": {
".": {},
}
},
"f:spec": {
".": {},
"f:lifecycleHooks": {},
"f:metadata": {},
"f:providerSpec": {
".": {},
"f:value": {
".": {},
"f:apiVersion": {},
"f:credentialsSecret": {
".": {},
"f:name": {}
},
"f:diskGiB": {},
"f:kind": {},
"f:memoryMiB": {},
"f:metadata": {
".": {},
"f:creationTimestamp": {}
},
"f:network": {
".": {},
"f:devices": {}
},
"f:numCPUs": {},
"f:numCoresPerSocket": {},
"f:snapshot": {},
"f:template": {},
"f:userDataSecret": {
".": {},
"f:name": {}
},
"f:workspace": {
".": {},
"f:datacenter": {},
"f:datastore": {},
"f:folder": {},
"f:resourcePool": {},
"f:server": {}
}
}
}
}
},
"manager": "machineset-controller",
"operation": "Update",
"time": "2023-07-07T15:34:29Z"
},
{
"apiVersion": "machine.openshift.io/v1beta1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:annotations": {
".": {},
"f:machine.openshift.io/instance-state": {}
},
"f:finalizers": {
".": {},
"v:\"machine.machine.openshift.io\"": {}
},
"f:labels": {
"f:machine.openshift.io/region": {},
"f:machine.openshift.io/zone": {}
}
},
"f:spec": {
"f:providerID": {}
}
},
"manager": "machine-controller-manager",
"operation": "Update",
"time": "2024-05-13T16:16:28Z"
},
{
"apiVersion": "machine.openshift.io/v1beta1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:status": {
"f:conditions": {}
}
},
"manager": "Go-http-client",
"operation": "Update",
"subresource": "status",
"time": "2025-01-15T17:49:31Z"
},
{
"apiVersion": "machine.openshift.io/v1beta1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:status": {
"f:lastUpdated": {},
"f:nodeRef": {}
}
},
"manager": "nodelink-controller",
"operation": "Update",
"subresource": "status",
"time": "2025-03-21T17:08:31Z"
},
{
"apiVersion": "machine.openshift.io/v1beta1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:status": {
".": {},
"f:addresses": {},
"f:phase": {},
"f:providerStatus": {
".": {},
"f:conditions": {},
"f:instanceId": {},
"f:instanceState": {},
"f:taskRef": {}
}
}
},
"manager": "machine-controller-manager",
"operation": "Update",
"subresource": "status",
"time": "2025-03-21T17:08:38Z"
}
],
"name": "my-cluster-worker-2xqdt",
"namespace": "openshift-machine-api",
"ownerReferences": [
{
"apiVersion": "machine.openshift.io/v1beta1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "MachineSet",
"name": "my-cluster-worker",
"uid": "57d19e1d-6533-4a76-ad21-f5109e18f357"
}
],
"resourceVersion": "475217234",
"uid": "927b2375-db4d-4547-b9a4-bf764a2fd13f"
},
"spec": {
"lifecycleHooks": {},
"metadata": {},
"providerID": "vsphere://423c21f0-c4f4-fa1e-c658-b7f68078f767",
"providerSpec": {
"value": {
"apiVersion": "machine.openshift.io/v1beta1",
"credentialsSecret": {
"name": "vsphere-cloud-credentials"
},
"diskGiB": 120,
"kind": "VSphereMachineProviderSpec",
"memoryMiB": 65536,
"metadata": {
"creationTimestamp": null
},
"network": {
"devices": [
{
"networkName": "my-network"
}
]
},
"numCPUs": 4,
"numCoresPerSocket": 4,
"snapshot": "",
"template": "my-cluster-rhcos",
"userDataSecret": {
"name": "worker-user-data"
},
"workspace": {
"datacenter": "my-data-center",
"datastore": "my-data-store",
"folder": "/openshift/my-cluster",
"resourcePool": "my-resource-pool",
"server": "server1"
}
}
}
},
"status": {
"addresses": [
{
"address": "10.11.12.13",
"type": "InternalIP"
},
{
"address": "169.254.169.2",
"type": "InternalIP"
},
{
"address": "fe80::87c8:6aef:95d6:c6b9",
"type": "InternalIP"
},
{
"address": "my-cluster-worker-2xqdt",
"type": "InternalDNS"
}
],
"conditions": [
{
"lastTransitionTime": "2023-07-07T15:34:30Z",
"status": "True",
"type": "Drainable"
},
{
"lastTransitionTime": "2024-10-09T18:57:56Z",
"status": "True",
"type": "InstanceExists"
},
{
"lastTransitionTime": "2023-07-07T15:34:30Z",
"status": "True",
"type": "Terminable"
}
],
"lastUpdated": "2025-03-21T17:08:31Z",
"nodeRef": {
"kind": "Node",
"name": "my-cluster-worker-2xqdt",
"uid": "b3b3bef4-3ed8-4170-a4a3-5195bcdb0c9b"
},
"phase": "Running",
"providerStatus": {
"conditions": [
{
"lastTransitionTime": "2023-07-07T15:34:32Z",
"message": "Machine successfully created",
"reason": "MachineCreationSucceeded",
"status": "True",
"type": "MachineCreation"
}
],
"instanceId": "423c21f0-c4f4-fa1e-c658-b7f68078f767",
"instanceState": "poweredOn",
"taskRef": "task-43063"
}
}
}
Did you find this article helpful?
If so, consider buying me a coffee over at