Kubernetes go client api for version of a node

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

returns the version for a particular node. How do I do this using client-go?

-- Gao.Xin
client-go
kubernetes
version

1 Answer

4/23/2020

Sample code for getting Kubernetes version from NodeInfo using Go-client:

// 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)
-- Kamol Hasan
Source: StackOverflow