Use local disk volumes

Last updated:2021-05-11 10:41:17

You can use local disk volumes in the following ways:

  • hostPath: Mount the file directory of the host where a container resides to a specified mount point in the container. If the container needs to access /etc/hosts, hostPath can be mapped to /etc/hosts.
  • emptyDir: Data is stored in a temporary directory. The lifecycle of this type of local disk volume is the same as that of the associated pod. If the pod is deleted, emptyDir is also deleted, and data is permanently lost.

hostPath

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        imagePullPolicy: Always
        name: nginx
        volumeMounts:
        - mountPath: /data
          name: hostpath
      volumes:
      - hostPath:
          path: /var
        name: hostpath

emptyDir

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        imagePullPolicy: Always
        name: nginx
        volumeMounts:
        - mountPath: /data
          name: emptydir
      volumes:
      - emptyDir: {}
        name: emptydir

Note:
If the source path of a local disk volume is empty, the system allocates a temporary directory, which is **/data/kubelet/pods/pod_id/volumes/kubernetes.io~empty-dir. **.
The lifecycle of the temporary local disk volume is the same as that of the associated pod.

Did you find the above information helpful?

Unhelpful
Mostly Unhelpful
A little helpful
Helpful
Very helpful

What might be the problems?

Insufficient
Outdated
Unclear or awkward
Redundant or clumsy
Lack of context for the complex system or functionality

More suggestions

0/200

Please give us your feedback.

Submitted

Thank you for your feedback.

问题反馈