gpt4 book ai didi

kubernetes - kubectl pod部署后不存在k8s initContainer mountPath

转载 作者:行者123 更新时间:2023-12-02 11:51:54 24 4
gpt4 key购买 nike

下面是部署yaml,部署后,我可以访问pod
我可以看到mountPath“/ usr / share / nginx / html”,但是找不到
“/ work-dir”应该由initContainer创建。
有人可以解释一下原因吗?
谢谢和Rgds

apiVersion: v1
kind: Pod
metadata:
name: init-demo
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
# These containers are run during pod initialization
initContainers:
- name: install
image: busybox
command:
- wget
- "-O"
- "/work-dir/index.html"
- http://kubernetes.io
volumeMounts:
- name: workdir
mountPath: "/work-dir"
dnsPolicy: Default
volumes:
- name: workdir
emptyDir: {}

最佳答案

“/ work-dir”处的卷由init容器安装,而“/ work-dir”位置仅存在于init容器中。当init容器完成时,其文件系统消失了,因此init容器中的“/ work-dir”目录已“消失”。应用程序(nginx)容器也挂载相同的卷(尽管位于不同的位置),从而为两个容器提供共享其内容的机制。

根据docs:

Init containers can run with a different view of the filesystem than app containers in the same Pod.

关于kubernetes - kubectl pod部署后不存在k8s initContainer mountPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58808519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com