Kubernetes Mounting Volumes in Pods: Difference between revisions
No edit summary |
|||
Line 7: | Line 7: | ||
=Overview= | =Overview= | ||
Specifies how the volumes declared in the [[Kubernetes_Pod_Manifest#volumes_manifest|volumes section of the manifest]] are to be mounted (projected) into the container's filesystem. Mounting the same volume (specified by its name) multiple times, with different mount characteristics, such different mount points, subPaths, etc. is permitted. | |||
Mounting the same volume (specified by its name) multiple | |||
=<tt>volumeMounts</tt> Pod Manifest Section= | =<tt>volumeMounts</tt> Pod Manifest Section= | ||
Line 26: | Line 24: | ||
The identifier of the volume. Must match the name the volume specification was declared under, in the [[Kubernetes_Pod_Manifest#volumes|volumes]] section of the specification. Is the same volume is used for multiple mount points, those mount points should refer the same volume name. | The identifier of the volume. Must match the name the volume specification was declared under, in the [[Kubernetes_Pod_Manifest#volumes|volumes]] section of the specification. Is the same volume is used for multiple mount points, those mount points should refer the same volume name. | ||
==<tt>mountPath</tt>== | |||
Specifies the path within the container where the volume will be mounted. Must not contain ':'. | 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. | 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. | ||
==<tt>subPath</tt>== | |||
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). <code>subPath</code> value must be a relative, the metadata will cause a deployment error if "/" or a path that starts with "/" is used. | 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). <code>subPath</code> value must be a relative, the metadata will cause a deployment error if "/" or a path that starts with "/" is used. | ||
Line 48: | Line 38: | ||
is a noop - the metadata will be accepted as correct, and the external volume's root will be mounted. | is a noop - the metadata will be accepted as correct, and the external volume's root will be mounted. | ||
==<tt>subPathExpr</tt>== | |||
Expanded path within the volume from which the container's volume should be mounted. Behaves similarly to [[#subPath|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. | Expanded path within the volume from which the container's volume should be mounted. Behaves similarly to [[#subPath|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. | ||
==<tt>readOnly</tt>== | |||
Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. | Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. | ||
=Use Cases= | |||
* Storage | * Storage | ||
* [[Kubernetes_Secrets_Operations#Consume_a_Secret_as_a_File|Secrets projected as files]] | * [[Kubernetes_Secrets_Operations#Consume_a_Secret_as_a_File|Secrets projected as files]] |
Revision as of 03:09, 3 January 2021
External
Internal
Overview
Specifies how the volumes declared in the volumes section of the manifest are to be mounted (projected) into the container's filesystem. Mounting the same volume (specified by its name) multiple times, with different mount characteristics, such different mount points, subPaths, etc. is permitted.
volumeMounts Pod Manifest Section
kind: Pod spec: containers: - name: 'test' ... volumeMounts: - name: 'mount-0' mountPath: '/red' # 'orange' must exist in the root of the volume identified by 'mount-0'; the content of that # directory will be exposed in the container under the '/red' directory. subPath: 'orange'
name
The identifier of the volume. Must match the name the volume specification was declared under, in the volumes section of the specification. Is the same volume is used 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
- Storage
- Secrets projected as files