Kubernetes Mounting Volumes in Pods

From NovaOrdis Knowledge Base
Revision as of 21:44, 2 January 2021 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

External

Internal

Overview

Mounting the same volume (specified by its name) multiple time, with different mount characteristics, such different mount points, subPaths, etc. is permitted.

TODO consolidate with Pod Manifest - volumeMounts.

volumeMounts Pod Manifest Section

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#volumemount-v1-core

Specifies how the volumes declared in the volumes section of the manifest are to be mounted (projected) into the container's filesystem.

Also see:

Mounting a Volume in a Pod

name

The identifier of the volume. Must match the name the volume specification was declared under, in the volumes section of the specification.

If we need to use the same volume for multiple mount points, those mount points should refer the same volume name.

mountPath

Specifies the path within the container where the volume will be mounted. Must not contain ':'.

The mount will succeed even if some or all intermediate path elements of the "mountPath" does not exist as directories in the container's file system - they will be created as necessary.

subPath

Specifies the relative path within the external volume, relative to the root of the external volume, whose content will be mounted as container's volume. If the path does not exist on the external volume, it will be created. If not specified, defaults to "" (external volume's root). subPath value must be a relative, the metadata will cause a deployment error if "/" or a path that starts with "/" is used.

Specifying:

  subPath: ''

is a noop - the metadata will be accepted as correct, and the external volume's root will be mounted.

subPathExpr

Expanded path within the volume from which the container's volume should be mounted. Behaves similarly to subPath but environment variable references $(VAR_NAME) are expanded using the container's environment. Defaults to "" (volume's root). subPathExpr and subPath are mutually exclusive.

readOnly

Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false.

Use Cases