<p>For example, in terminal, we can do so via <code>kubectl version</code>.</p>
<p>I wish to obtain the kubernetes server version via Golang codes. I believe it should be covered by the <code>client-go</code> (k8s.io/client-go/kubernetes) and/or <code>controller-runtime</code> (sigs.k8s.io/controller-runtime) codes, but couldn't find any.</p>
<p>What is the most efficient way to retrieve the kubernetes server version?</p>

jtee
<p>you can use this package:</p>
<blockquote>
<p>&quot;k8s.io/client-go/discovery&quot;</p>
</blockquote>
<p>call this function: <code>discovery.NewDiscoveryClientForConfig(cfg)</code> which returns <code>DiscoveryClient</code> object which you can use to call <code>discClient.ServerVersion()</code></p>
<p><code>cfg</code> in the above function is the kubeconfig of the cluster that you can provide, which you can get by calling the function: <code>config.GetConfigOrDie()</code> from this package</p>
<blockquote>
<p>&quot;sigs.k8s.io/controller-runtime/pkg/client/config&quot;</p>
</blockquote>
