6

My kubernetes clusters' nodes all have small root partitions. Is it possible to configure k8s to use an alternate location for emptyDir volumes?

DjPadz
  • 61
  • 3
  • Not that I'm aware of, a potential alternative (depending on what you are trying to achieve) might be using `hostPath` instead of `emptyDir`? – donhector Feb 20 '20 at 20:52

1 Answers1

1

As it is described in documentation:

By default, emptyDir volumes are stored on whatever medium is backing the node - that might be disk or SSD or network storage, depending on your environment. However, you can set the emptyDir.medium field to "Memory" to tell Kubernetes to mount a tmpfs (RAM-backed filesystem) for you instead. While tmpfs is very fast, be aware that unlike disks, tmpfs is cleared on node reboot and any files you write will count against your Container’s memory limit.

You have to specify spec.containers.volumeMounts path and later use it in spec.volumes. Like in this example:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

More detailed information and more examples you can find on this tutorial.

Hope it will help.

PjoterS
  • 615
  • 3
  • 11
  • 9
    This doesn't answer the original question. DjPadz wasn't asking if it's possible to mount the emptydir inside the container in a different location, but instead, if it is possible to tell kuberenetes to use a specific path on the host for emptydir backing storage, instead of having it together with everything else the cluster is using. This is useful in case the k8s host node has a scratch disk or something. – John Blackberry Dec 23 '19 at 11:05