0
[root@gx dashboard]# kubectl get node
NAME       STATUS   ROLES    AGE     **VERSION**
minikube   Ready    master   7d20h   **v1.15.0**

返回特定节点的版本。如何使用 client-go 执行此操作?

4

1 回答 1

2

NodeInfo使用 Go-client获取 Kubernetes 版本的示例代码:

// Create clientset 
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
  panic(err.Error())
}

// Get node object
node, err := clientset.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
if err != nil {
  panic(err.Error())
}

// You can read Kubernetes version from either KubeletVersion or KubeProxyVersion
kVersion := node.Status.NodeInfo.KubeletVersion
// kVersion := node.Status.NodeInfo.KubeProxyVersion
fmt.Println(kVersion)
于 2020-04-23T07:12:13.833 回答