Emptydir and Hostpath

Source: Internet
Author: User

Directory

    • Volume type
    • Emptydir
    • Hostpath
Volume type

Volume is a shared directory accessed by multiple containers in the Kubernetes pod. Volume is defined on the pod and is mounted to the same or different paths by multiple containers of the pod. The life cycle of the volume is the same as that of the pod, and the container stops and restarts in the pod generally does not affect the data in volume. So the general volume is used to persist the data generated by the pod.

Kubernetes offers a wide range of volume types, including Emptydir, Hostpath, NFS, Glusterfs, CEPHFS, Ceph RBD, and more. Refer to the official documentation for details.

In this article we briefly say Emptydir and Hostpath.

Emptydir

The Emptydir type of volume is created when the pod is assigned to node, and Kubernetes automatically assigns a directory on node, so there is no need to specify the corresponding directory file on the host node. The initial contents of this directory are empty, and when the pod is removed from node, the data in the Emptydir is permanently deleted.

Emptydir volume is primarily used for some applications that do not require permanent storage of temporary directories, multiple containers for shared directories, and so on.

The following is an example of a pod mount Emptydir:

apiVersion: v1kind: Podmetadata:  name: test-podspec:  containers:  - image: test-webserver    name: test-container    volumeMounts:    - name: cache-volume      mountPath: /cache  volumes:  - name: cache-volume    emptyDir: {}
Hostpath

Hostpath volume is a directory or file on the pod Mount host, allowing the container to be stored using a host's high-speed file system. The disadvantage is that, in k8s, the pod is dynamically dispatched on the node nodes. When a pod is started on the current node node and the file is stored locally via Hostpath, the file stored on the previous node cannot be used the next time it is scheduled to start on another node.

Hostpath Use Example:

apiVersion: v1kind: Podmetadata:  name: test-podspec:  containers:  - image: test-webserver    name: test-container    volumeMounts:    - name: test-volume      mountPath: /www  volumes:  - name: test-volume    hostPath:      path: /data

Emptydir and Hostpath

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.