Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get container's disk usage in Kubernetes (without docker command)?

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

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

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

like image 881
adebasi Avatar asked Nov 15 '18 21:11

adebasi


People also ask

Can I deploy in Kubernetes without Docker?

Can you use Kubernetes without Docker? As Kubernetes is a container orchestrator, it needs a container runtime in order to orchestrate. Kubernetes is most commonly used with Docker, but it can also be used with any container runtime.

Where are volumes stored in Kubernetes?

For any kind of volume in a given pod, data is preserved across container restarts. At its core, a volume is a directory, possibly with some data in it, which is accessible to the containers in a pod.


1 Answers

Yes, but currently not with kubectl, you can get metrics from the kubelet, either through the kube-apiserver (proxied) or directly calling the kubelet HTTP(s) server endpoint (default port 10250). Disk metrics are generally available on the /stats/summary endpoint and you can also find some cAdvisor metrics on the /metrics/cavisor endpoint.

For example, to get the 'usedBytes' for the first container in the first pod returned through the kube-apiserver:

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

The Bearer token can be a service account token tied to a ClusterRole like this:

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
like image 183
Rico Avatar answered Sep 20 '22 10:09

Rico