Volumes

Similar to docker volumes, containers inside pod in kubernetes can also have volumes in specification.

pod.yaml

spec:
    containers:
        - volumeMounts:
            - name: shared
              mountPath: /shared # inside container
    volumes:
        - name: shared
          hostPath:
            - type: Directory
              path: /shared # inside host/node

This should mount the container path /shared to host path /shared. /shared should be present on host prior to mounting it.

hostPath is one of the implementation of volume where host path is used as storage. Using hostPath is not an ideal choice and impose several security risks to the host being used. There are other implementations such as nfs etc.

References

  1. https://kubernetes.io/docs/concepts/storage/volumes/
  2. https://kubernetes.io/docs/concepts/storage/volumes/#volume-types
  3. https://kubernetes.io/docs/concepts/storage/volumes/#hostpath