Detailed explanation of Kubernetes data storage mechanism

1. Data volume type in K8s

We all know that containers and Pods are short-lived. That is to say their life cycle may be short, they will be destroyed and created frequently. When the container is destroyed, the data stored in the container's internal file system will be cleared.

In order to persist the data stored in the container, we can use Kubernetes Volume. The life cycle of the Volume is independent of the container. The container in the Pod may be destroyed and rebuilt, but the Volume will be retained.

In fact, a Kubernetes Volume is a directory, which is similar to a Docker Volume. When a Volume is mounted to a Pod, all containers in the Pod can access the Volume. Kubernetes Volume also supports multiple types of data storage, including emptyDir, hostPath, GCE Persistent Disk, NFS, Ceph, etc.

Volume provides an abstraction of various storages. When a container uses Volume to read and write data, it does not need to care whether the data is stored in the file system of the local node or stored on the cloud disk. To it, all types of Volume are just a directory.

2. EmptyDir type storage

EmptyDir is the most basic type of Volume. It should be noted that emptyDir Volume is persistent for containers, but not for Pods. When a Pod is deleted from a node, the contents of the Volume are also deleted. But if only the container is destroyed and the Pod is still there, the Volume will not be affected.

That is to say: the life cycle of emptyDir Volume is consistent with that of Pod.

[root@master data]# more pods.yml 
apiVersion: v1
kind: Pod
metadata:
  name: share-pods
spec:
 containers:
  - n

Guess you like

Origin blog.csdn.net/qq_35029061/article/details/132201035