A, volume

1, emptyDir
create an empty volume of the container to mount the Pod. Pod delete the volume will be deleted.
Scenarios: Pod data sharing between the container

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: write
    image: centos
    command: ["bash","-c","for i in {1..100};do echo $i >> /data/hello;sleep 1;done"]
    volumeMounts:
     - name: data
       mountPath: /data 
  - name: read
    image: centos
    command: ["bash","-c","tail -f /data/hello"]
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    emptyDir: {}

kubectl logs   my-pod -c read

2, hostPath
mount the file system or Node directory Pod in the container.
Application scenarios: Pod in containers need access to the host file, such as monitoring host

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: busybox
    image: busybox
    args:
    - /bin/sh
    - -c
    - sleep 36000
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    hostPath:
      path: /tmp
      type: Directory

3, a network storage (NFS)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  selector:
    matchLabels:
      app: nginx  
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
        - name: wwwroot
          mountPath: /usr/share/nginx/html
        ports:
        - containerPort: 80
      volumes:
      - name: wwwroot
        nfs:
          server: 192.168.0.200
          path: /data/nfs

 

Guess you like

Origin www.cnblogs.com/xw115428/p/11958286.html