I use a volume with hostPath, so I can share files between my local host and the pods. My question is: Is there a way to limit how much sapce an hostpath volume can consume by those pods, like ephemeral storage request/limit? What happens if the container consumed all space on host's local directory?
volumes:
- hostPath:
path: "/search/data/app"
name: app
No. This is not a current feature.
@coderanger and @DavidMaze are right* but I would like to back it up with some more context.
A hostPath volume mounts a file or directory from the host node's filesystem into your Pod. This is not something that most Pods will need, but it offers a powerful escape hatch for some applications.
For example, some uses for a
hostPath
are:
running a container that needs access to Docker internals; use a
hostPath
of/var/lib/docker
running cAdvisor in a container; use a
hostPath
of /sysallowing a Pod to specify whether a given
hostPath
should exist prior to the Pod running, whether it should be created, and what it should exist as
hostPath
is not recommended due to several reasons:
You don't directly control which node your pods will run on, so you're not guaranteed that the pod will actually be scheduled on the node that has the data volume.
You expose your cluster to security threats.
If a node goes down you need the pod to be scheduled on other node where your locally provisioned volume will not be available.
And regarding the potential limiting of the hostPath
volumes:
The storage media (such as Disk or SSD) of an
emptyDir
volume is determined by the medium of the filesystem holding the kubelet root dir (typically/var/lib/kubelet
). There is no limit on how much space anemptyDir
orhostPath
volume can consume, and no isolation between containers or between pods.
*as always :)
EDIT:
Including the suggestion from VASャ and making the answer a community wiki one.
I would try create separate LVM partitions and use their mount points as a Pod's Hostpath target directory. In that case container won't consume more than the LVM partition size. It may add some maintenance cost though. Consider to use iscsi volumes as an alternative storage option.