I'm experimenting with kubectl -o=custom-columns and I wonder if there is a way to get node status. I'm can get the nodename with this
k get nodes -o=custom-columns=NAME:.metadata.name
but is there a way to get the node status (ready, notready)?
It is not so easy, beacuse it depends of amount of infgoramtin about your worker, for example:
"conditions": [
{
"lastHeartbeatTime": "2019-07-26T13:04:26Z",
"lastTransitionTime": "2019-07-26T13:04:26Z",
"message": "Weave pod has set this",
"reason": "WeaveIsUp",
"status": "False",
"type": "NetworkUnavailable"
},
{
"lastHeartbeatTime": "2019-08-09T11:21:02Z",
"lastTransitionTime": "2019-06-29T14:23:33Z",
"message": "kubelet has sufficient memory available",
"reason": "KubeletHasSufficientMemory",
"status": "False",
"type": "MemoryPressure"
},
{
"lastHeartbeatTime": "2019-08-09T11:21:02Z",
"lastTransitionTime": "2019-06-29T14:23:33Z",
"message": "kubelet has no disk pressure",
"reason": "KubeletHasNoDiskPressure",
"status": "False",
"type": "DiskPressure"
},
{
"lastHeartbeatTime": "2019-08-09T11:21:02Z",
"lastTransitionTime": "2019-06-29T14:23:33Z",
"message": "kubelet has sufficient PID available",
"reason": "KubeletHasSufficientPID",
"status": "False",
"type": "PIDPressure"
},
{
"lastHeartbeatTime": "2019-08-09T11:21:02Z",
"lastTransitionTime": "2019-07-25T17:06:09Z",
"message": "kubelet is posting ready status. AppArmor enabled",
"reason": "KubeletReady",
"status": "True",
"type": "Ready"
}
],
for bare metal cluster so in this case your command will be:
kubectl get no -ocustom-columns=Name:metadata.name,Status:status.conditions[4].type
but for gke node
"conditions": [
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:09:41Z",
"message": "docker overlay2 is functioning properly",
"reason": "CorruptDockerOverlay2",
"status": "False",
"type": "CorruptDockerOverlay2"
},
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:04:39Z",
"message": "kernel has no deadlock",
"reason": "KernelHasNoDeadlock",
"status": "False",
"type": "KernelDeadlock"
},
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:04:39Z",
"message": "Filesystem is not read-only",
"reason": "FilesystemIsNotReadOnly",
"status": "False",
"type": "ReadonlyFilesystem"
},
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:09:41Z",
"message": "node is functioning properly",
"reason": "UnregisterNetDevice",
"status": "False",
"type": "FrequentUnregisterNetDevice"
},
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:09:41Z",
"message": "kubelet is functioning properly",
"reason": "FrequentKubeletRestart",
"status": "False",
"type": "FrequentKubeletRestart"
},
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:09:42Z",
"message": "docker is functioning properly",
"reason": "FrequentDockerRestart",
"status": "False",
"type": "FrequentDockerRestart"
},
{
"lastHeartbeatTime": "2019-08-09T11:26:19Z",
"lastTransitionTime": "2019-07-31T14:09:43Z",
"message": "containerd is functioning properly",
"reason": "FrequentContainerdRestart",
"status": "False",
"type": "FrequentContainerdRestart"
},
{
"lastHeartbeatTime": "2019-08-02T13:32:49Z",
"lastTransitionTime": "2019-08-02T13:32:49Z",
"message": "NodeController create implicit route",
"reason": "RouteCreated",
"status": "False",
"type": "NetworkUnavailable"
},
{
"lastHeartbeatTime": "2019-08-09T11:27:03Z",
"lastTransitionTime": "2019-07-31T14:04:40Z",
"message": "kubelet has sufficient memory available",
"reason": "KubeletHasSufficientMemory",
"status": "False",
"type": "MemoryPressure"
},
{
"lastHeartbeatTime": "2019-08-09T11:27:03Z",
"lastTransitionTime": "2019-07-31T14:04:40Z",
"message": "kubelet has no disk pressure",
"reason": "KubeletHasNoDiskPressure",
"status": "False",
"type": "DiskPressure"
},
{
"lastHeartbeatTime": "2019-08-09T11:27:03Z",
"lastTransitionTime": "2019-07-31T14:04:40Z",
"message": "kubelet has sufficient PID available",
"reason": "KubeletHasSufficientPID",
"status": "False",
"type": "PIDPressure"
},
{
"lastHeartbeatTime": "2019-08-09T11:27:03Z",
"lastTransitionTime": "2019-07-31T14:04:41Z",
"message": "kubelet is posting ready status. AppArmor enabled",
"reason": "KubeletReady",
"status": "True",
"type": "Ready"
}
],
so it will be
kubectl get nodes -o=custom-columns=NAME:.metadata.name,STATUS:.status.conditions[11].type
Try to execute:
$ kubectl get nodes -o=custom-columns=NAME:.metadata.name,STATUS:.status.conditions[12].type
More information about custom-columns you can find here: custom-columns.
Useful article: custom-column-example.
Try to run kubectl get nodes
as following:
kubectl get nodes -o custom-columns=STATUS:status.conditions[-1].type