This topic describes how to configure an emptyDir volume to use memory as the storage media.

Virtual Kubelet mode

  • You can configure an emptyDir volume to use memory as the storage media by setting the medium field to Memory in the configuration file of a pod to which the emptyDir volume is mounted. An emptyDir volume that uses memory as the storage media can be mounted to any directory, such as /dev/shm.
apiVersion: v1
kind: Pod
metadata:
  name: cos-vk-empty-memory
spec:
  nodeName: virtual-kubelet
  containers:
  - image: nginx
    name: u2
    volumeMounts:
    - mountPath: /dev/shm
      name: sd
  volumes:
  - name: sd
    emptyDir:
      medium: Memory
			

API mode

  • You can configure an emptyDir volume to use memory as the storage media by adding Volume.1.EmptyDirVolume.Medium=Memory to the request parameters of an API call.
  • Pay attention to the memory size if you configure an emptyDir volume to use memory as the storage media. If you store too many files in the emptyDir volume, the issue of out of memory (OOM) may occur.

  • The storage size of an emptyDir volume that uses memory as the storage media is half of the total memory on the node where the volume is run. Currently, you cannot change the storage size of an emptyDir volume that uses memory as the storage media.

  • An emptyDir that does not use memory as the storage media will not occupy any system memory.