$ oc set volume <object_selection> <operation> <mandatory_parameters> <options>
Files in a container are ephemeral. As such, when a container crashes or stops, the data is lost. You can use volumes to persist the data used by the containers in a pod. A volume is directory, accessible to the Containers in a pod, where data is stored for the life of the pod.
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. Containers are not persistent by default; on restart, their contents are cleared.
To ensure that the file system on the volume contains no errors and, if errors
are present, to repair them when possible, OpenShift Container Platform 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 set volume
to add and remove volumes and
volume mounts for any object that has a pod template like replication controllers or
deployment configs. You can also list volumes in pods or any
object that has a pod template.
The oc set volume
command uses the following general syntax:
$ oc set volume <object_selection> <operation> <mandatory_parameters> <options>
Specify one of the following for the object_selection
parameter in the oc set volume
command:
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. |
|
Specify --add
or --remove
for the operation
parameter in the oc set volume
command.
Any mandatory parameters are specific to the selected operation and are discussed in later sections.
Any options are specific to the selected operation and are discussed in later sections.
You can list volumes and volume mounts in pods or pod templates:
To list volumes:
$ oc set volume <object_type>/<name> [options]
List volume supported options:
Option | Description | Default |
---|---|---|
|
Name of the volume. |
|
|
Select containers by name. It can also take wildcard |
|
For example:
To list all volumes for pod p1:
$ oc set volume pod/p1
To list volume v1 defined on all deployment configs:
$ oc set volume dc --all --name=v1
You can add volumes and volume mounts to a pod.
To add a volume, a volume mount, or both to pod templates:
$ oc set 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. Do not mount to the container root, |
|
|
Host path. Mandatory parameter for |
|
|
Name of the secret. Mandatory parameter for |
|
|
Name of the configmap. 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. |
|
For example:
To add a new volume source emptyDir to the registry DeploymentConfig
object:
$ oc set volume dc/registry --add
You can alternatively apply the following YAML to add the volume: Sample deployment config with an added volume
|
To add volume v1 with secret secret1 for replication controller r1 and mount inside the containers at /data:
$ oc set volume rc/r1 --add --name=v1 --type=secret --secret-name='secret1' --mount-path=/data
You can alternatively apply the following YAML to add the volume: Sample replication controller with added volume and secret
|
To 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 DeploymentConfig
object on the server:
$ oc set volume -f dc.json --add --name=v1 --type=persistentVolumeClaim \
--claim-name=pvc1 --mount-path=/data --containers=c1
You can alternatively apply the following YAML to add the volume: Sample deployment config with persistent volume added
|