Shell 如何访问kubernetes容器init上的图像内容
我有一个图像,其中包含/usr/data/webroot中的数据。此数据应在容器init上移动到/var/www/html 现在我踩在了我的脚上。据我所知,它可以用于在容器初始化时执行任务 但我不知道任务是在创建amo magento吊舱后执行的,还是init任务运行,然后创建magento吊舱 我假设当initContainers任务运行时,带有magento映像的容器不可用,因此没有可移动到新目录的内容Shell 如何访问kubernetes容器init上的图像内容,shell,kubernetes,containers,init,Shell,Kubernetes,Containers,Init,我有一个图像,其中包含/usr/data/webroot中的数据。此数据应在容器init上移动到/var/www/html 现在我踩在了我的脚上。据我所知,它可以用于在容器初始化时执行任务 但我不知道任务是在创建amo magento吊舱后执行的,还是init任务运行,然后创建magento吊舱 我假设当initContainers任务运行时,带有magento映像的容器不可用,因此没有可移动到新目录的内容 apiVersion: apps/v1 kind: Deployment metadat
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
但我不知道任务是在创建amo magento吊舱后执行的,还是init任务运行,然后创建magento吊舱
当然是后者,这就是为什么您能够为initContainers:
任务指定一个完全不同的图像:
——它们之间的关联仅在于它们运行在同一节点上,并且如您所见,共享卷。好吧,我说了“当然”,但你有一点用词不当:在那之后,magner
容器被创建了-initContainers:
和容器:
容器的集合就是Pod
如果我理解您的问题,您的部署的修复方法就是将initContainer:
中的映像更新为包含magic/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
然后当容器[0]
启动时,PVC将包含您期望的数据
这就是说,我实际上非常确定您想从这个故事中删除PVC,因为根据定义,它在Pod重新启动时是持久的,因此只会随着时间的推移积累文件(因为您的sh
命令在将文件移到那里之前,当前不会清理/www
)。如果您将所有那些pvc
引用替换为emptyDir:{}
引用,那么这些目录将始终是“新的”并且始终只包含在您的initContainer:
中声明的标记图像的内容。解决方案确实不是使用busybox,而是使用amo magento图像作为InitContainers。但是我没有使用空目录,而是加载了pvc。第二次坐骑是没有必要的。