<p>I have a Kubernetes Cluster and want to know how much disk space my containers use. I am not talking about mounted Volumes.</p>

<p>I can get this information by using docker commands like <code>docker system df -v</code> or <code>docker ps -s</code>, but I don't want to connect to every single worker node.</p>

<p>Is there a way to get a container's disk usage via <code>kubectl</code> or are there kubelet metrics where I can get this information from?</p>

adebasi
<p>Yes, but currently not with kubectl, you can get metrics from the <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/" rel="noreferrer">kubelet</a>, either through the kube-apiserver (proxied) or directly calling the kubelet HTTP(s) server endpoint (default port <code>10250</code>). Disk metrics are generally available on the <code>/stats/summary</code> endpoint and you can also find some <a href="https://github.com/google/cadvisor" rel="noreferrer">cAdvisor</a> metrics on the <code>/metrics/cavisor</code> endpoint.</p>

<p>For example, to get the 'usedBytes' for the first container in the first pod returned through the <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/" rel="noreferrer">kube-apiserver</a>:</p>

<pre><code>$ curl -k -s -H 'Authorization: Bearer &lt;REDACTED&gt;' \
  https://kube-apiserver:6443/api/v1/nodes/&lt;node-name&gt;/proxy/stats/summary \
  | jq '.pods[0].containers[0].rootfs.usedBytes'
</code></pre>

<p>The Bearer token can be a service account token tied to a ClusterRole like this:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
  name: myrole
rules:
- apiGroups:
  - ""
  resources:
  - nodes
  - nodes/proxy
  verbs:
  - get
  - list
  - watch
- nonResourceURLs:
  - /metrics
  - /api/*
  verbs:
  - get
</code></pre>
