Docker and k8s: k8s volumes 'emptyDir'

Peter Jeon·2023년 4월 17일

Docker and k8s

목록 보기
9/41

Kubernetes emptyDir

In this blog post, we will explore the emptyDir volume type in Kubernetes (k8s) and how it can be used with Docker containers. The emptyDir volume type provides ephemeral storage that can be shared between containers running in the same pod.

What is an emptyDir Volume?

What is an emptyDir Volume?

emptyDir is a Kubernetes volume type that provides an ephemeral storage space on a node's disk. This storage space is created when a pod is assigned to a node and is deleted when the pod is removed from the node. The data stored in an emptyDir volume is only available as long as the pod is running on the node and is not persistent across node or pod restarts.

Use Cases for emptyDir Volumes

Use Cases for emptyDir Volumes

  1. Cache directories: Storing temporary files, such as a cache, that can be shared between containers in a pod.
  2. Scratch space: Providing a temporary workspace for containers to perform tasks like file processing or transformation.
  3. IPC: Sharing data between containers in a pod using files, enabling inter-process communication.

Creating an emptyDir Volume

Creating an emptyDir Volume

To create an emptyDir volume, you need to define it in the pod configuration file. Here's an example pod configuration that creates an emptyDir volume named "my-emptydir" and mounts it to two containers:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  volumes:
  - name: my-emptydir
    emptyDir: {}
  containers:
  - name: container-1
    image: my-image-1
    volumeMounts:
    - name: my-emptydir
      mountPath: /mnt
  - name: container-2
    image: my-image-2
    volumeMounts:
    - name: my-emptydir
      mountPath: /mnt

Limitations of emptyDir Volumes

  1. Ephemeral storage: Data in an emptyDir volume is not persistent and will be lost when the pod is removed from the node.
  2. No data redundancy: There is no replication or backup of the data stored in an emptyDir volume.
  3. Storage capacity: The storage capacity of an emptyDir volume is limited to the available disk space on the node.

Conclusion

The emptyDir volume type in Kubernetes is a useful tool for creating ephemeral storage that can be shared between containers within a pod. It is suitable for temporary data storage, such as caches or scratch spaces, but it should not be used for storing critical or long-lived data.

profile
As a growing developer, I am continually expanding my skillset and knowledge, embracing new challenges and technologies

0개의 댓글