0

As a beginner in container administration, I can't find a clear description of OpenShift's deployment stages and related YAML statements, specifically when persistent volume mounting and shell commands execution are involved. For example, in the RedHat documentation there is a lot of examples. A simple one is 16.4. Pod Object Definition:

apiVersion: v1
kind: Pod
metadata:
  name: busybox-nfs-pod
  labels:
    name: busybox-nfs-pod
spec:
  containers:
  - name: busybox-nfs-pod
    image: busybox
    command: ["sleep", "60000"]
    volumeMounts:
    - name: nfsvol-2
      mountPath: /usr/share/busybox
      readOnly: false
  securityContext:
    supplementalGroups: [100003]
    privileged: false
  volumes:
  - name: nfsvol-2
    persistentVolumeClaim:
      claimName: nfs-pvc

Now the question is: does the command sleep (or any other) execute before or after the mount of nfsvol-2 is finished? In other words, is it possible to use the volume's resources in such commands? And if it's not possible in this config, then which event handlers to use instead? I don't see any mention about an event like volume mounted.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
Stan
  • 8,683
  • 9
  • 58
  • 102

1 Answers1

0

does the command sleep (or any other) execute before or after the mount of nfsvol-2 is finished?

To understand this, lets dig into the underlying concepts for Openshift.

OpenShift is a container application platform that brings docker and Kubernetes to the enterprise. So Openshift is nothing but an abstraction layer on top of docker and kubernetes along with additional features.

Regarding the volumes and commands lets consider the following example:

Let's run the docker container by mounting a volume, which is the home directory of host machine to the root path of the container(-v is option to attach volume).

$ docker run -it -v /home:/root ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
50aff78429b1: Pull complete 
f6d82e297bce: Pull complete 
275abb2c8a6f: Pull complete 
9f15a39356d6: Pull complete 
fc0342a94c89: Pull complete 
Digest: sha256:f871d0805ee3ce1c52b0608108dbdf1b447a34d22d5c7278a3a9dd78fc12c663
Status: Downloaded newer image for ubuntu:latest
root@1f07f083ba79:/# cd /root/
root@1f07f083ba79:~# ls
lost+found  raghavendralokineni  raghu  user1
root@1f07f083ba79:~/raghavendralokineni# pwd
/root/raghavendralokineni

Now execute the sleep command in the container and exit.

root@1f07f083ba79:~/raghavendralokineni# sleep 10
root@1f07f083ba79:~/raghavendralokineni# 
root@1f07f083ba79:~/raghavendralokineni# exit

Check the files available in the /home path which we have mounted to the container. This content is same as that of /root path in the container.

raghavendralokineni@iconic-glider-186709:/home$ ls
lost+found  raghavendralokineni  raghu  user1

So when a volume is mounted to the container, any changes in the volume will be effected in the host machine as well.

Hence the volume will be mounted along with the container and commands will be executed after container is started.

Coming back to the your YAML file,

volumeMounts:
    - name: nfsvol-2
      mountPath: /usr/share/busybox

It says ,mount the volume nfsvol-2 to the container and the information regarding the volume is mentioned in volumes:

volumes:
  - name: nfsvol-2
    persistentVolumeClaim:
      claimName: nfs-pvc

So mount the volume to the container and execute the command which is specifed:

containers:
  - name: busybox-nfs-pod
    image: busybox
    command: ["sleep", "60000"]

Hope this helps.

Here_2_learn
  • 5,013
  • 15
  • 50
  • 68
  • Thanks for your answer. Probably my question was stated not so clear as it should. The question is not about mounting of a volume containing running image, but an external persistent volume which is attached/mounted, AFACU, after the moment the image is already started. This is why I'm not sure, if the shell command will be excuted before or after or in undetermined moment of the external volume availability. Also I'm not sure that OpenShift runs the same workflow as in your standalone docker example. – Stan Dec 21 '17 at 11:02
  • to add further, volume mounted can be be either host machine storage or any other external storage which is either attached or mounted. These external storage can be attached with persistentvolumeclaims which are mentioned in the "volumes" of your YAML. Secondly, you cannot attach a storage after the image is already started. Volumes should be configured before starting the image. Regarding the flow in openshift, it will be same as way that is explained in standalone docker example as underlying concepts are docker and K8s. – Here_2_learn Dec 21 '17 at 13:32