<p>I have installed minikube in a VIM and I have service account token with all the privileges. Is there any API from kubernetes to fetch the resource usage(Overall).</p>

<p>To get CPU and Memory usage you can use (depending on the object you like to see) the following:</p>

<p><code>kubectl top pods</code>
or
<code>kubectl top nodes</code>
which will show you</p>

<pre><code>$ kubectl top pods
NAME                       CPU(cores)   MEMORY(bytes)
nginx-1-5d4f8f66d9-xmhnh   0m           1Mi
</code></pre>

<p>Api reference might look like the following:</p>

<p><code>$ curl http://localhost:8080/apis/metrics.k8s.io/v1beta1/pods</code></p>

<pre><code>...
{
      "metadata": {
        "name": "nginx-1-5d4f8f66d9-xmhnh",
        "namespace": "default",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/nginx-1-5d4f8f66d9-xmhnh",
        "creationTimestamp": "2019-07-29T11:48:13Z"
      },
      "timestamp": "2019-07-29T11:48:11Z",
      "window": "30s",
      "containers": [
        {
          "name": "nginx",
          "usage": {
            "cpu": "0",
            "memory": "1952Ki"
          }
        }
      ]
    }
...
</code></pre>

<p>As for API there is few ways of accessing it.</p>

<p>You can use <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#using-kubectl-proxy" rel="nofollow noreferrer">proxy</a> by running <code>kubectl proxy --port:8080 &amp;</code></p>

<blockquote>
  <p>The following command runs kubectl in a mode where it acts as a reverse proxy. It handles locating the API server and authenticating.</p>
  
  <p>See  <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands/#proxy" rel="nofollow noreferrer">kubectl proxy</a>  for more details.</p>
  
  <p>Then you can explore the API with curl, wget, or a browser, like so:</p>
  
  <p><code>curl http://localhost:8080/api/</code></p>
</blockquote>

<p>You can access it <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#without-kubectl-proxy" rel="nofollow noreferrer">without proxy</a> by using authentication token.</p>

<blockquote>
  <p>It is possible to avoid using kubectl proxy by passing an authentication token directly to the API server, like this:</p>
  
  <p>Using  <code>grep/cut</code>  approach:</p>
</blockquote>

<pre class="lang-sh prettyprint-override"><code># Check all possible clusters, as you .KUBECONFIG may have multiple contexts:
kubectl config view -o jsonpath='{"Cluster name\tServer\n"}{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'

# Select name of cluster you want to interact with from above output:
export CLUSTER_NAME="some_server_name"

# Point to the API server refering the cluster name
APISERVER=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$CLUSTER_NAME\")].cluster.server}")

# Gets the token value
TOKEN=$(kubectl get secrets -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='default')].data.token}"|base64 -d)

# Explore the API with TOKEN
curl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
</code></pre>

<p>And you can also access the API using several official client libraries for example <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#go-client" rel="nofollow noreferrer">Go</a> or <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#python-client" rel="nofollow noreferrer">Python</a>. Other libraries are available to see <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/" rel="nofollow noreferrer">here</a>.</p>
