如何通过客户端获取Kubernetes节点的状态?

问题描述

我想通过 go 客户端获取 Kubernetes 中的节点列表及其状态。我在用 clientset.CoreV1().Nodes().List(metav1.ListOptions{}) 我能够获得节点列表和一些信息,例如节点标签,但我在那里找不到 status.phase(对于给我状态的 pod)。

我搜索并找到了 NodeCondition (https://github.com/kubernetes/api/blob/9b64426eca51a74faa7cc9bd732a533d339c69c2/core/v1/types.go#L4911),但我找不到任何有关如何使用它的文档,而且我自己也无法使其工作。有人可以告诉我如何通过客户端获取节点的状态吗?

解决方法

您可以通过 implementation 'com.google.android.filament:filament-android:1.9.9' implementation 'com.google.android.filament:filament-utils-android:1.9.9' implementation 'com.google.android.filament:gltfio-android:1.9.9'

访问它
node.Status.Condition

打印:

nodes,_ := client.CoreV1().Nodes().List(context.TODO(),metav1.ListOptions{})

for _,node := range nodes.Items {
    fmt.Printf("%s\n",node.Name)
    for _,condition := range node.Status.Conditions {
        fmt.Printf("\t%s: %s\n",condition.Type,condition.Status)
    }
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...