Chapter 13 of the storage volume

The life cycle of the file on the disk container is short, which makes there will be some problems when running important applications in the container. First, when the collapse of the container, kubelet will restart it, but the container file will be lost - the container in a clean state (mirroring the initial state) restart. Second, Pod run simultaneously in a plurality of containers, usually you need to share files between the containers. Kubernetes in Volume abstract good solution to these problems

 

1 , background

Kubernetes volumes in clear life - the package it Pod same. The f to life than the volume of the Pod are all long container when the container restart data is still preserved. Of course, when the Pod is no longer present, the volume will cease to exist. Perhaps more importantly, Kubernetes support multiple types of volume, Pod can use any number of volumes at the same time

2 , the volume type

 

 

 

3 , emptyDir

When the Pod is allocated to a node, first create emptyDir roll, and as long as the Pod running on that node, the volume will exist. As the name of the volume, which is initially empty. Pod in the container can read and write emptyDir the same file volume, the same or different paths although the volume can be mounted to each container. When removed from the nodes for any reason Pod time, emptyDir data will be permanently deleted

emptyDir usage are:

① scratch space, such as a disk-based merge sort

② checkpoint when used for a long time to calculate crash recovery

③ Web server container provides data, save the contents of the container extracted file manager

apiVersion: v1

kind: Pod

metadata:

 name: test-pd

spec:

 containers:

 - image: k8s.gcr.io/test-webserver

name: test-container

 volumeMounts:

- mountPath: /cache

 name: cache-volume

 volumes:

- name: cache-volume

 emptyDir: {}

 

4hostPathhostPath

Volume file system of the host node in a file or directory is mounted to the cluster

hostPath following uses:

① operation requires access Docker interior of the container; use / var / lib / docker of hostPath

② run in a container cAdvisor ; use / dev / cgroups of hostPath

③ allows the pod to specify a given hostPath Should the pod exist before you run, whether to create, and what form it should exist

 

In addition to the desired path than the attribute, the user can also hostPath volume specified type

 

Empty string (the default) for backward compatibility, which means that the mount hostPath no checks are performed before the volume

value

behavior

 

Empty string (the default) for backward compatibility, which means that the mount hostPath no checks are performed before the volume

DirectoryOrCreate

If nothing exists on a given path, then there will be needed to create an empty directory permissions set to 0755 , and Kubelet have the same group and ownership.

Directory

To be present at a given directory path

FileOrCreate

If nothing exists on a given path, you will need to create an empty file in accordance with permissions set to 0644 , and Kubelet have the same group and ownership.

File

To file must exist at a given path

Socket

You must be present at a given path UNIX socket

CharDevice

Under a given path must exist a character device

block Device

Under a given path must exist block device

 

With this volume type is Note that because:

① Due to file on each node are different, have the same configuration (for example, from podTemplate created) the pod behavior on different nodes may be different

② When Kubernetes When you add a resource-aware scheduling according to plan, will not consider hostPath use of resources

③ file or directory created on the underlying host only by the root write. You need to be in a privileged container root identity running processes, file permissions or modify the host to write hostPath volume

apiVersion: v1

kind: Pod

metadata:

 name: test-pd

spec:

containers:

    - image: k8s.gcr.io/test-webserver

name: test-container

 volumeMounts:

 - mountPath: /test-pd

 name: test-volume

volumes:

- name: test-volume

hostPath:

# directory location on host

path: /data

# this field is optional type: Directory

Guess you like

Origin www.cnblogs.com/LiuQizhong/p/11613723.html