OpenShift的YAML执行优先于卷安装和命令

问题描述 投票:0回答:1

作为容器管理的初学者,我无法找到OpenShift部署阶段和相关YAML语句的清晰描述,特别是涉及持久性卷安装和shell命令执行时。例如,在RedHat文档中有一个lot of examples。一个简单的是16.4。 Pod对象定义:

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

现在问题是:sleep(或任何其他)命令在nfsvol-2安装完成之前或之后执行了吗?换句话说,是否可以在这些命令中使用卷的资源?如果在这个配置中不可能,那么使用哪个事件处理程序呢?我没有看到有关像装载卷这样的事件的任何提及。

event-handling openshift lifecycle mount openshift-3
1个回答
0
投票

命令sleep(或任何其他)在nfsvol-2挂载完成之前或之后执行?

为了理解这一点,让我们深入了解Openshift的基本概念。

OpenShift是一个容器应用程序平台,它将docker和Kubernetes引入企业。因此,Openshift只是docker和kubernetes之上的抽象层以及其他功能。

关于卷和命令,请考虑以下示例:

让我们通过将一个卷(主机的主目录)安装到容器的根路径来运行docker容器(-v是附加卷的选项)。

$ 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

现在在容器中执行sleep命令并退出。

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

检查我们已挂载到容器的/ home路径中的可用文件。此内容与容器中/ root路径的内容相同。

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

因此,当卷安装到容器时,卷中的任何更改也将在主机中生效。

因此,卷将与容器一起安装,并且在容器启动后将执行命令。

回到你的YAML文件,

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

它说,将卷nfsvol-2安装到容器中,并在卷中提到有关卷的信息:

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

因此,将卷装入容器并执行指定的命令:

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

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.