<p>I have deployed the metric-server on my kubernetes cluster and it's just working fine as I run the following command:</p>

<pre><code>kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes
</code></pre>

<p>I want to access the metric-server from a pod. For that, I use the <code>service/metric-server</code>'s IP and it is in the same namespace that the metric-server is. The way I'm trying to access to the metric is like this:</p>

<pre><code>    myurl := fmt.Sprintf("https://%s:%s/apis/metrics.k8s.io/v1beta1/nodes/", serviceHost, servicePort)
    u, err := url.Parse(myurl)
    if err != nil {
        panic(err)
    }
    req, err := http.NewRequest(httpMethod, u.String(), nil)
    if err != nil {
        log.Printf("Cant sned req: %s", err)
    }
    caToken, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
    if err != nil {
        panic(err) // cannot find token file
    }

    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", string(caToken)))

    caCertPool := x509.NewCertPool()
    caCert, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
    if err != nil {
        panic(err)
    }
    caCertPool.AppendCertsFromPEM(caCert)

    client := &amp;http.Client{
        Transport: &amp;http.Transport{
            TLSClientConfig: &amp;tls.Config{
                RootCAs: caCertPool,
            },
        },
    }

    resp, err := client.Do(req)
    if err != nil {
        log.Printf("sending helm deploy payload failed: %s", err.Error())
        panic(err)
    }

</code></pre>

<p>This is not working nad the <code>logs</code> result for the pod is:</p>

<pre><code>Get https://METRIC-SERVER-SERVICE-IP/apis/metrics.k8s.io/v1beta1/nodes: x509: certificate is valid for 127.0.0.1, not METRIC-SERVER-SERVICE-IP
</code></pre>

<p>Is this the right way to access the metric-server from a pod?</p>

mR.aTA
<p>what i did so i can access the metrics-server on a local deployment:</p>

<ol>
<li>set proper rbac</li>
<li>inside the pod : 
export CURL_CA_BUNDLE=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
curl -H "Authorization: Bearer $TOKEN" -k <a href="https://10.100.123.57/apis/metrics.k8s.io/v1beta1/nodes" rel="nofollow noreferrer">https://10.100.123.57/apis/metrics.k8s.io/v1beta1/nodes</a></li>
</ol>
