k8s volume storage

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

empty for a simple empty directory to store temporary data.
 
hostPath - is used to mount the directory from the file system nodes to work in a pod
 
gitRepo by detecting a Git repository to initialize the contents of the volume.
 
nfs - NFS mount the pod in a shared volume.
 
configMap secret downwardAPI for a particular type of resource and the cluster information portion Kubemetes disclosed pod to roll

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
View Code
Media for specified EMPTYDIR
As emptyDir volume to be used, it is carried on an actual disk pod working node created, depending on the performance of this type of disk nodes. But we can notice the presence of memory Kubemete tmfs file system rather than drive to create emptyDir. Therefore, emptyDir medium to  Memory
volumes: 
- name: html
  emptyDir
    medium: Memory
View Code

Use Git repository as storage volumes

gitRepo emptyDir volume is substantially the volume, and it starts at the pod (specific version detected but before creating the data to fill the container) by cloning Git repository. gitRepo emptyDir container as the same volume, essentially a directory dedicated specifically for containers comprising volume and alone.
 
When the pod is deleted, the volumes and their contents are deleted. However, other types of volumes does not create a new directory, but the directory is mounted to existing external pod container file system. Contents of the volume may be stored multiple instances of the pod

 

Notice:

After creating gitRepo volume, it does not keep pace and the corresponding repo, when submitting the new push to the Git repository, the volume of files will not be updated. However, if used pod is managed by the ReplicationController, delete this pod will trigger create a new pod, pod and will this new volume contains the latest submitted
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: . 
View Code

Tips: 

In order to achieve pod gitrepo git repository directory and real-time synchronization can sidecar container

 

Guess you like

Origin www.cnblogs.com/fanggege/p/12188123.html