How is volume size of HostPath mount determined?

8/7/2020

Now I got a logs volume:

      - name: log
        hostPath:
          path: /opt/cloud/logs/sample

and when I execute cd /opt/cloud/logs/sample;df -h ., it shows:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G   11G   27G  29% /opt/cloud/logs/sample

My question is: where is the 40G number came from? Is there a way to limit this to another number like 30GB? What happens if the container used up 40G, get evicted or the disk size just magically bump to a higher number?

Edit

I just find out 40G is the size of host disk. But if I use an emptyDir instead of hostPath, it only got 9.8G size,which corresponded to size of /mnt/paas/kubernetes/kubelet on the host, which I have no idea what it is or why it is 9.8G.

k8s version:

Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.9", GitCommit:"16236ce91790d4c75b79f6ce96841db1c843e7d2", GitTreeState:"clean", BuildDate:"2019-03-25T06:40:24Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.10-r1-CCE2.0.28.B001", GitCommit:"0de6083f712a799642f25141c60fdeff34d5514c", GitTreeState:"clean", BuildDate:"2019-10-30T14:19:27Z", GoVersion:"go1.11.13", Compiler:"gc", Platform:"linux/amd64"}
-- Nick Allen
kubernetes

1 Answer

8/7/2020
  • where is the 40G number came from?

    The hostPath volume type is a node filesystem volume, volume is determined by the medium of the filesystem holding the kubelet root dir.

  • Is there a way to limit this to another number like 30GB?

There is no limit on how much space an emptyDir or hostPath volume can consume, and no isolation between Containers or between Pods.

  • What happens if the container used up 40G, get evicted or the disk size just magically bump to a higher number?

Your pod will have write error because the filesystem will be full.

-- Philidor
Source: StackOverflow