Kubernetes section Volume type introduction and YAML example

Source: Internet
Author: User
Tags tmp file


1. Emptydir (Local data volume)


The Emptydir type of volume is created when the pod is dispatched to a host, and the container within the same pod can read and write to the same file in the Emptydir. Once the pod has left the host, the data in the EMPTYDIRR will be permanently deleted. So the current Emptydir type of volume is primarily used as a temporary space, persistent volume kubernetes such as a Web server write log or a temp directory required by the TMP file. The YAML example is as follows:

kubernetes volumes


[email protected] demon2]# cat Test-emptypath.yaml
Apiversion:v1 kubernetes persistent volume
Kind:pod
Metadata
Labels
Name:test-emptypath
Role:master kubernetes volume mounts
Name:test-emptypath
Speckubernetes volume
Containers
-Name:test-emptypath
image:registry:5000/back_demon:1.0
Volumemounts:kubernetes volume mount
-Name:log-storage
Mountpath:/home/laizy/test/
Command
-/run.sh
Volumes
-Name:log-storage
Emptydir: {}


2. Hostdir (Local data volume)


The volume of the Hostdir property allows the corresponding container to access the specified directory on the current host. For example, if you need to run a container that accesses the Docker system directory, use the/var/lib/docker directory as a hostdir type volume, or run cadvisor inside a container, kubernetes persistent volume claim use/dev/ Cgroups directory as a hostdir type of volume. Once the pod has left the host, the data in the Hostdir will not be permanently deleted, but the data will not be migrated to other hosts on the pod. Therefore, it is important to note that the hostdir of the same pod may behave differently on different host hosts because the file system structure and content on each host are not necessarily identical. A yaml example is shown below



[email protected] demon2]# cat Test-hostpath.yaml
Apiversion:v1
Kind:pod
Metadata
Labels
Name:test-hostpath
Role:master
Name:test-hostpath
Spec
Containers
-Name:test-hostpath
image:registry:5000/back_demon:1.0
Volumemounts:
-Name:ssl-certs
Mountpath:/home/laizy/test/cert
Readonly:true
Command
-/run.sh
Volumes
-Name:ssl-certs
Hostpath:
Path:/etc/ssl/certs


3. NFS (Network data volume)


The volume of the NFS type. Allows an existing network hard disk to be shared between containers within the same pod. The YAML example is as follows:

kubernetes persistent volumes example


[email protected] demon2]# cat Test-nfspath.yaml
Apiversion:v1
Kind:pod
Metadata
Labels
Name:test-nfspath
Role:master
Name:test-nfspath
Spec
Containers
-Name:test-nfspath
image:registry:5000/back_demon:1.0
Volumemounts:
-Name:nfs-storage
Mountpath:/home/laizy/test/
Command
-/run.sh
Volumes
-Name:nfs-storage
Nfs:
server:192.168.20.47
Path: "/data/disk1"


volume mount kubernetes



4, Secret (Information data volume)


Kubemetes provides secret to handle sensitive data, such as passwords, tokens, and keys, and secret provides a more secure mechanism (BASE64 encryption) to prevent data leakage than to configure sensitive data directly in the pod definition or image. Secret is created independently of the pod, mounted in the form of a data volume into the pod, secret data is saved as a file, and the container can fetch the required data by reading the file. The YAML example is as follows:



[email protected] demon2]# cat Secret.yaml
Apiversion:v1
Kind:secret
Metadata
Name:mysecret
Type:opaque
Data
Username:emhlbnl1
Password:ewfvzglkawfv
[email protected] demon2]# cat Test-secret.yaml
Apiversion:v1
Kind:pod
Metadata
Labels
Name:test-secret
Role:master
Name:test-secret
Spec
Containers
-Name:test-secret
image:registry:5000/back_demon:1.0
Volumemounts:
-Name:secret
Mountpath:/home/laizy/secret
Readonly:true
Command
-/run.sh
Volumes
-Name:secret
Secret
Secretname:mysecret






Kubernetes section Volume type introduction and YAML example


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.