<p>Basically, my kubeconfig file has:</p>
<pre><code>apiVersion: v1
clusters:
 - cluster:
      server: &lt;OAM ip address&gt; this is what I want
(...)
</code></pre>
<p>I want to get the server address.
Previously searching , I've found this solution:</p>
<pre><code>config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, *kubeconfig)
if err != nil {
    panic(err.Error())
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
    panic(err.Error())
}

nodes, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
    panic(err)
}
nodeip := []corev1.NodeAddress{}
for i := 0; i &lt; len(nodes.Items); i++ {
    nodeip = nodes.Items[i].Status.Addresses
    fmt.Println(nodeip[0].Address)
}
fmt.Println(nodes.Items[0].Status.Addresses)
</code></pre>
<p>But it gives me the Internal IP, not the OAM server IP (which is inside the Kubernetes config file)</p>

<p>If you want the server address from the <code>kubeconfig</code> file, just read it from your <code>config</code> variable:</p>
<pre><code>package main

import (
    &quot;flag&quot;
    &quot;fmt&quot;
    &quot;path/filepath&quot;

    &quot;k8s.io/client-go/kubernetes&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
    &quot;k8s.io/client-go/util/homedir&quot;
)

func main() {
    var kubeconfig *string

    if home := homedir.HomeDir(); home != &quot;&quot; {
        kubeconfig = flag.String(&quot;kubeconfig&quot;, filepath.Join(home, &quot;.kube&quot;, &quot;config&quot;), &quot;(optional) absolute path to the kubeconfig file&quot;)
    } else {
        kubeconfig = flag.String(&quot;kubeconfig&quot;, &quot;&quot;, &quot;absolute path to the kubeconfig file&quot;)
    }

    flag.Parse()

    config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, *kubeconfig)
    if err != nil {
        panic(err)
    }

    fmt.Printf(&quot;server: %s\n&quot;, config.Host)
}
</code></pre>
<hr />
<p>If you're curious what other fields are available on the <code>rest.Config</code> object, a quick solution is to print out the <code>config</code> variable using the <code>%+v</code> format specifier:</p>
<pre><code>fmt.Printf(&quot;%+v\n&quot;, config)
</code></pre>
<p>For more details, look at the <a href="https://pkg.go.dev/k8s.io/client-go/rest#Config" rel="nofollow noreferrer">reference documentation</a>.</p>
