Scenarios
Data pod in the container with the restart pod, deletion will disappear, some scenarios require persistent data, then you need to mount the volume.
Tips:
volumes is an integral part of the pod, so as in the specification as the container is defined in the pod. They are not independent Kubernetes resource object can not be created or deleted separately. All containers pod can be used in the volume, but it must first be mounted on each of the containers need to access it in. In each container, the volume can be mounted anywhere in its file system.
Common type
Configuration operation
empty Configuration
emptyDir type is created when the Pod assigned to Volume Node, Kubernetes automatically assigns a directory on Node, it is not necessary to specify the host corresponding to the file directory on the Node. The initial contents of this directory is empty, when the Pod removed from the Node, the data emptyDir will be permanently deleted. emptyDir Volume is mainly used in certain applications without having to permanently save the temporary directory, shared directory plurality of containers and so on.
In the definition of Pod
apiVersion: VL kind: Pod Metadata: name: Fortune spec: Containers: - Image: Luksa / # Fortune first vessel called HTML- asdf name: HTML - asdf volumeMounts: - name: # HTML container mounted local volumes HTML MountPath: / var / the htdocs # container mounted to this directory - Image: Nginx: Alpine name: Web -server second vessel called # WEB- Server volumeMounts: - name: # HTML container mounted local volumes HTML MountPath: / usr / report this content share / nginx /read-only HTML # readOnly: to true the ports: - containerPort: 80 Protocol: the TCP Volumes - name: # designated HTML HTML emptyDir: {volume} of type # emptyDir
volumes: - name: html emptyDir medium: Memory
Use Git repository as storage volumes
Notice:
apiVersion: vl kind: Pod metadata: name: gitrepo-vol-pod spec: containers: - image: nginx:alpine name: web-server volumeMounts : - name : html mountPath: /usr/share/nginx/html readOnly: true ports: - containerPort: 80 protocol: TCP volumes: - name: html #容器挂载的本地卷为 html gitRepo: repository: https://github.com/kzf/asdf-website-example.git revision: master directory: .
Tips:
In order to achieve pod gitrepo git repository directory and real-time synchronization can sidecar container