client-go 获取 k8s node 节点信息

//获取NODE
fmt.Println("####### 获取node ######")
nodes, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
	panic(err)
}
for _,nds := range nodes.Items {
	fmt.Printf("NodeName: %s\n", nds.Name)
}

//获取 指定NODE 的详细信息
fmt.Println("\n ####### node详细信息 ######")
nodeName := "k8s-master2"
nodeRel, err := clientset.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
if err != nil {
	panic(err)
}
fmt.Printf("Name: %s \n", nodeRel.Name)
fmt.Printf("CreateTime: %s \n", nodeRel.CreationTimestamp)
fmt.Printf("NowTime: %s \n", nodeRel.Status.Conditions[0].LastHeartbeatTime)
fmt.Printf("kernelVersion: %s \n", nodeRel.Status.NodeInfo.KernelVersion)
fmt.Printf("SystemOs: %s \n", nodeRel.Status.NodeInfo.OSImage)
fmt.Printf("Cpu: %s \n", nodeRel.Status.Capacity.Cpu())
fmt.Printf("docker: %s \n", nodeRel.Status.NodeInfo.ContainerRuntimeVersion)
// fmt.Printf("Status: %s \n", nodeRel.Status.Conditions[len(nodes.Items[0].Status.Conditions)-1].Type)
fmt.Printf("Status: %s \n", nodeRel.Status.Conditions[len(nodeRel.Status.Conditions)-1].Type)
fmt.Printf("Mem: %s \n", nodeRel.Status.Allocatable.Memory().String())

猜你喜欢

转载自blog.csdn.net/u011327801/article/details/92154555