我有一个图像,其中包含/usr/ data /webroot内部的数据。这些数据应该在容器init上移动到/var/www/html。
现在我偶然发现了InitContainers。据我所知,它可以用于执行容器初始化任务。
但我不知道任务是在创建amo-magento豆荚之后被执行,还是init任务运行,然后创建magento吊舱。
我假设在运行initContainers任务时,带有magento图像的容器不可用,因此没有任何内容可以移动到新目录。
apiVersion: apps/v1
kind: Deployment
metadata:
name: amo-magento
labels:
app: amo-magento
spec:
replicas: 1
selector:
matchLabels:
app: amo-magento
template:
metadata:
labels:
app: amo-magento
tier: frontend
spec:
initContainers:
- name: setup-magento
image: busybox:1.28
command: ["sh", "-c", "mv -r /magento/* /www"]
volumeMounts:
- mountPath: /www
name: pvc-www
- mountPath: /magento
name: magento-src
containers:
- name: amo-magento
image: amo-magento:0.7 # add google gcr.io path after upload
imagePullPolicy: Never
volumeMounts:
- name: install-sh
mountPath: /tmp/install.sh
subPath: install.sh
- name: mage-autoinstall
mountPath: /tmp/mage-autoinstall.sh
subPath: mage-autoinstall.sh
- name: pvc-www
mountPath: /var/www/html
- name: magento-src
mountPath: /usr/data/webroot
# maybe as secret - can be used as configMap because it has not to be writable
- name: auth-json
mountPath: /var/www/html/auth.json
subPath: auth.json
- name: php-ini-prod
mountPath: /usr/local/etc/php/php.ini
subPath: php.ini
# - name: php-memory-limit
# mountPath: /usr/local/etc/php/conf.d/memory-limit.ini
# subPath: memory-limit.ini
volumes:
- name: magento-src
emptyDir: {}
- name: pvc-www
persistentVolumeClaim:
claimName: magento2-volumeclaim
- name: install-sh
configMap:
name: install-sh
# kubectl create configmap mage-autoinstall --from-file=build/docker/mage-autoinstall.sh
- name: mage-autoinstall
configMap:
name: mage-autoinstall
- name: auth-json
configMap:
name: auth-json
- name: php-ini-prod
configMap:
name: php-ini-prod
# - name: php-memory-limit
# configMap:
# name: php-memory-limit发布于 2019-05-20 01:58:16
但我不知道任务是在创建amo-magento豆荚之后被执行,还是init任务运行,然后创建magento吊舱。
可以肯定的是,这就是为什么您能够为您的任务指定一个完全不同的 image: --它们只相互关联,因为它们运行在相同的节点上,并且,正如您所看到的,共享卷。好吧,我说的是“当然”,但您的用词有点不恰当:在此之后,创建了magneto containers -- Pod是每一个同位容器、initContainers:容器和container:容器的集合。
如果我理解您的问题,您的Deployment的修正就是将initContainer:中的image:更新为包含神奇/usr/data/webroot的/usr/data/webroot,然后更新shell命令以引用图像中的正确路径:
initContainers:
- name: setup-magento
image: your-magic-image:its-magic-tag
command: ["sh", "-c", "mv -r /usr/data/webroot/* /www"]
volumeMounts:
- mountPath: /www
name: pvc-www
# but **removing** the reference to the emptyDir volume然后,当container[0]启动时,PVC将包含您期望的数据。
尽管如此,我实际上非常肯定您希望从这个故事中删除PVC,因为--根据定义--它在Pod重新引导过程中是持久的,因此只会随着时间的推移积累文件(因为您的sh命令在将文件移到那里之前没有清理/www )。如果您将所有pvc引用替换为emptyDir: {}引用,那么这些目录将始终是“新的”,并且始终只包含initContainer:中声明的标记图像中的内容。
https://stackoverflow.com/questions/56212386
复制相似问题