<p>I currently have metric server installed and running in my K8s cluster.</p>

<p>Utilizing the the kubernetes python lib, I am able to make this request to get pod metrics:</p>

<pre><code>from kubernetes import client

api_client = client.ApiClient()
ret_metrics = api_client.call_api(
            '/apis/metrics.k8s.io/v1beta1/namespaces/' + 'default' + '/pods', 'GET',
            auth_settings=['BearerToken'], response_type='json', _preload_content=False)
response = ret_metrics[0].data.decode('utf-8')
print('RESP', json.loads(response))
</code></pre>

<p>In the response, for each pod all containers will be listed with their cpu and memory usage:</p>

<pre><code>'containers': [{'name': 'elasticsearch', 'usage': {'cpu': '14122272n', 'memory': '826100Ki'}}]}
</code></pre>

<p>Now my question is how do i get these metrics for the pod itself and not its containers? I'd rather not have to sum up the metrics from each container if possible. Is there any way to do this with metrics-server? </p>

bbmhmmad
<p>Based on the <a href="https://github.com/kubernetes/kubernetes/blob/release-1.14/pkg/kubelet/server/stats/handler.go#L123-L126" rel="nofollow noreferrer">official repository</a> you can query <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/" rel="nofollow noreferrer">kubelet</a> stats endpoint:</p>

<pre><code>$ curl --insecure https://&lt;node url&gt;:10250/stats/summary
</code></pre>

<p>which will return stats of full pods. If you want to see metrics for pod/container itself, type:</p>

<pre><code>$ curl --insecure https://&lt;node url&gt;:10250/{namespace}/{podName}/{uid}/{containerName}
</code></pre>

<p>Let's take a look for example:</p>

<pre><code>{ "podRef": 
    { "name": "py588590", 
      "namespace": "myapp", 
      "uid": "e0056f1a" 
    }, 
  "startTime": "2019-10-16T03:57:47Z", 
  "containers": 
    [ 
      { "name": "py588590", 
        "startTime": "2019-10-16T03:57:50Z"
      }
    ]
}
</code></pre>

<p>These requests will works:</p>

<pre><code>http://localhost:10255/stats/myapp/py588590/e0056f1a/py588590
</code></pre>

<p>You can also look for this <a href="http://pivotal-cf-blog-staging.cfapps.io/post/secure-kubelet-metrics/" rel="nofollow noreferrer">article</a>. I hope it will helps you.</p>
