
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
Let's say you have a deployment named "my-deployment".
~]# oc get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
my-deployment 1/1 1 1 8d
The oc set volume command can be used to mount a local directory in a container, meaning that the directory and all of the files in the directory on the OpenShift server will be mounted in the container.
- -p or --path is the location of the directory that you want to mount on the host machine (the OpenShift system)
- -m or --mount-path is option, and is where the directory will be mounted in the container. If this option is not used, the volume will be available in the container.
~]$ oc set volume deployment my-deployment --add --type hostPath --path /usr/local/files --mount-path /data/files --name files
info: Generated volume name: volume-879rj
deployment.apps/my-deployment volume updated
The oc get deployment command with the --output yaml option can be used to see that the deployment now has volume and volumeMounts.
type can be:
- Empty = no checks are performmed
- DirectoryOrCreate = Create directory if it doesn't exist, with 0755 permissions
- Directory = Directory must exist
- FileOrCreate = Create file if it doesn't exist, with 0644 permissions
- File = File must exist
- Socket = Unix socket must exist
- CharDevice = Character device must exist
- BlockDevice = Block device must exist
~]$ oc get deployment my-deployment --output yaml
spec:
template:
spec:
containers:
volumeMounts:
- mountPath: /data/files
name: files
volumes:
- hostPath:
path: /usr/local/files
type: ""
name: files
AVOID TROUBLE
When attempting to mount a file, hostPath volumes are not allowed to be used may be returned. Check out my article on troubleshooting hostPath volumes are not allowed to be used.
And here is an example YAML to mount a file on the host system (/usr/local/files/foo.txt) in the container.
~]$ oc get deployment my-deployment --output yaml
spec:
template:
spec:
containers:
volumeMounts:
- mountPath: /data/files/foo.txt
name: myfile
volumes:
- name: myfile
hostPath:
path: /usr/local/files/foo.txt
type: File
Did you find this article helpful?
If so, consider buying me a coffee over at