$ oc volume <object_selection> <operation> <mandatory_parameters> <optional_parameters>
Containers are not persistent by default; on restart, their contents are cleared. Volumes are mounted file systems available to pods and their containers which may be backed by a number of host-local or network attached storage endpoints.
To ensure that the file system on the volume contains no errors and, if errors
are present, to repair them when possible, OpenShift Enterprise invokes the fsck
utility prior to the mount
utility. This occurs when either adding a volume or
updating an existing volume.
The simplest volume type is EmptyDir
, which is a temporary directory on a
single machine. Administrators may also allow you to request a
persistent volume that is automatically attached
to your pods.
|
You can use the CLI command oc volume
to add,
update, or remove volumes and
volume mounts for any object that has a pod template like
replication
controllers or
deployment
configurations. You can also list volumes in pods or any
object that has a pod template.
The oc volume
command uses the following general syntax:
$ oc volume <object_selection> <operation> <mandatory_parameters> <optional_parameters>
This topic uses the form <object_type>/<name>
for <object_selection>
in later examples. However, you can choose one of the following options:
Syntax | Description | Example |
---|---|---|
|
Selects |
|
|
Selects |
|
|
Selects resources of type |
|
|
Selects all resources of type |
|
|
File name, directory, or URL to file to use to edit the resource. |
|
The <operation>
can be one of --add
, --remove
, or --list
.
Any <mandatory_parameters>
or <optional_parameters>
are specific to the
selected operation and are discussed in later sections.
To add a volume, a volume mount, or both to pod templates:
$ oc volume <object_type>/<name> --add [options]
Option | Description | Default |
---|---|---|
|
Name of the volume. |
Automatically generated, if not specified. |
|
Name of the volume source. Supported values: |
|
|
Select containers by name. It can also take wildcard |
|
|
Mount path inside the selected containers. |
|
|
Host path. Mandatory parameter for |
|
|
Name of the secret. Mandatory parameter for |
|
|
Name of the persistent volume claim. Mandatory parameter for
|
|
|
Details of volume source as a JSON string. Recommended if the desired volume
source is not supported by |
|
|
Display the modified objects instead of updating them on the server. Supported
values: |
|
|
Output the modified objects with the given version. |
|
Examples
Add a new volume source emptyDir to deployment configuration registry:
$ oc volume dc/registry --add
Add volume v1 with secret $ecret for replication controller r1 and mount inside the containers at /data:
$ oc volume rc/r1 --add --name=v1 --type=secret --secret-name='$ecret' --mount-path=/data
Add existing persistent volume v1 with claim name pvc1 to deployment configuration dc.json on disk, mount the volume on container c1 at /data, and update the deployment configuration on the server:
$ oc volume -f dc.json --add --name=v1 --type=persistentVolumeClaim \ --claim-name=pvc1 --mount-path=/data --containers=c1
Add volume v1 based on Git repository https://github.com/namespace1/project1 with revision 5125c45f9f563 for all replication controllers:
$ oc volume rc --all --add --name=v1 \ --source='{"gitRepo": { "repository": "https://github.com/namespace1/project1", "revision": "5125c45f9f563" }}'
Updating existing volumes or volume mounts is the same as
adding volumes, but with the --overwrite
option:
$ oc volume <object_type>/<name> --add --overwrite [options]
Examples
Replace existing volume v1 for replication controller r1 with existing persistent volume claim pvc1:
$ oc volume rc/r1 --add --overwrite --name=v1 --type=persistentVolumeClaim --claim-name=pvc1
Change deployment configuration d1 mount point to /opt for volume v1:
$ oc volume dc/d1 --add --overwrite --name=v1 --mount-path=/opt
To remove a volume or volume mount from pod templates:
$ oc volume <object_type>/<name> --remove [options]
Option | Description | Default |
---|---|---|
|
Name of the volume. |
|
|
Select containers by name. It can also take wildcard |
|
|
Indicate that you want to remove multiple volumes at once. |
|
|
Display the modified objects instead of updating them on the server. Supported
values: |
|
|
Output the modified objects with the given version. |
|
Some examples:
Remove a volume v1 from deployment config d1:
$ oc volume dc/d1 --remove --name=v1
Unmount volume v1 from container c1 for deployment configuration d1 and remove the volume v1 if it is not referenced by any containers on d1:
$ oc volume dc/d1 --remove --name=v1 --containers=c1
Remove all volumes for replication controller r1:
$ oc volume rc/r1 --remove --confirm
To list volumes or volume mounts for pods or pod templates:
$ oc volume <object_type>/<name> --list [options]
List volume supported options:
Option | Description | Default |
---|---|---|
|
Name of the volume. |
|
|
Select containers by name. It can also take wildcard |
|
Examples
List all volumes for pod p1:
$ oc volume pod/p1 --list
List volume v1 defined on all deployment configurations:
$ oc volume dc --all --name=v1