Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Kubernetes emptyDir volume size

Tags:

kubernetes

I'm creating a ram based emptyDir volume for a pod.

 volumes:
  - name: ram-disk
    emptyDir:
      medium: "Memory"

Because this is a ram disk, I need to set the maximum size which it will take from the ram. Is there a parameter to set maximum size and minimum size?

like image 307
Dimuthu Avatar asked Jan 05 '16 11:01

Dimuthu


4 Answers

Adding an example (extending @flyer' answer):

apiVersion: v1
kind: Pod
...
spec:
  volumes:
    - emptyDir:
        sizeLimit: 1Gi
      name: log
like image 149
Vishrant Avatar answered Oct 08 '22 13:10

Vishrant


Since Kubernetes 1.20 there is the feature gate SizeMemoryBackedVolumes (currently alpha feature) which does exactly this.

Enable kubelets to determine the size limit for memory-backed volumes (mainly emptyDir volumes).

like image 37
Jasper Ben Avatar answered Oct 08 '22 12:10

Jasper Ben


For kubernetes-1.7.x, it's possible to set the sizeLimit for an EmptyDir.

like image 36
flyer Avatar answered Oct 08 '22 13:10

flyer


TL;DR: No, at least not for now.

This is an open issue, see 13479. Since I don't know your use case, I suppose my only suggestion is to try and use hostPath as a workaround, see also the docs for more details.

like image 40
Michael Hausenblas Avatar answered Oct 08 '22 13:10

Michael Hausenblas