Kubernetes get ephemeral-storage values

260 views Asked by At

I have pods with number of containers for each. I'm using

kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[?(@.name==<containerName>)].resources.limits.<resourceType>}{"\n"}{end}'|grep <podName>|head -n 1|awk '{print $2}'

to get cpu or memery limit values.

Now I want to have also the value of ephemeral-storage per container per pod.

    Limits:
      cpu:                350m
      ephemeral-storage:  164Mi
      memory:             512Mi
    Requests:
      cpu:                100m
      ephemeral-storage:  32Mi
      memory:             128Mi

Any idea how to get this?

I have tried

kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[?(@.name==<containerName>)].resources.limits.ephemeral-storage}{"\n"}{end}'|grep <podName>|head -n 1|awk '{print $2}'

but no luck

1

There are 1 answers

0
Srividya On

Pods use ephemeral local storage for scratch space, caching, and for logs. The kubelet can provide scratch space to Pods using local ephemeral storage to mount emptyDir volumes into containers.There is no way of calculating the ephemeral storage required for a pod and this depends on how much storage you are going to use. Depending on this we can set the right requests and limits in kubernetes(doc authored by Santhosh Nagaraj). You can learn more about how ephemeral storage can be managed & Ephemeral storage consumption management works from these documents.

Depending on your Kubernetes platform, you may not be able to easily determine where these files are being written, any filesystem can fill up, but rest assured that disk is being consumed somewhere depending on the specific configuration of your emptyDir and/or Kubernetes platform.

You can get a view of your ephemeral-storage usage way: Menu>Monitoring>Metrics Explorer> Resource type: kubernetes node & Metric: Ephemeral Storage.

Try the below commands to know kubernetes pod/container's ephemeral-storage usage details :

  1. Try du -sh / [run inside a container] : du -sh will give the space consumed by your container files which returns the amount of disk space the current directory and all those stuff in it are using as a whole.

  2. You can refer to the article Inspecting container filesystems written by Omid Azizi and use /bin/df as a tool to monitor ephemeral storage usage on the volume where ephemeral container data is located, which is /var/lib/kubelet and /var/lib/containers.