我正在尝试kubectl -o = custom-columns,我想知道是否有一种获取节点状态的方法。 我可以用
获得节点名k获取节点-o = custom-columns = NAME:.metadata.name
但是有没有办法获取节点状态(就绪,未就绪)?
答案 0 :(得分:2)
尝试如下运行kubectl get nodes
:
kubectl get nodes -o custom-columns=STATUS:status.conditions[-1].type
答案 1 :(得分:0)
尝试执行:
$ kubectl get nodes -o=custom-columns=NAME:.metadata.name,STATUS:.status.conditions[12].type
有关自定义列的详细信息,您可以在这里找到:custom-columns。
有用的文章:custom-column-example。
答案 2 :(得分:0)
这不是那么容易,因为它取决于对您的工人的英夫拉汀的量,例如:
"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"
}
],
对于裸机集群,在这种情况下,您的命令将是:
kubectl get no -ocustom-columns=Name:metadata.name,Status:status.conditions[4].type
但对于gke节点
"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"
}
],
所以会是
kubectl get nodes -o=custom-columns=NAME:.metadata.name,STATUS:.status.conditions[11].type