All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

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.

On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback