此部署创建了一个在其中包含init容器的pod。容器将卷装载到tmp/web-content中,并将单行“签出”写入index.html。
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-init-container
namespace: mars
spec:
replicas: 1
selector:
matchLabels:
id: test-init-container
template:
metadata:
labels:
id: test-init-container
spec:
volumes:
- name: web-content
emptyDir: {}
initContainers:
- name: init-con
image: busybox:1.31.0
command: ['sh', '-c' ,"echo 'check this out' > /tmp/web-content/index.html"]
volumeMounts:
- name: web-content
mountPath: /tmp/web-content/
containers:
- image: nginx:1.17.3-alpine
name: nginx
volumeMounts:
- name: web-content
mountPath: /usr/share/nginx/html
ports:
- containerPort: 80我启动临时吊舱,以检查我是否可以看到这一行“检查这”使用卷曲。
k run tmp --restart=Never --rm -i --image=nginx:alpine -- curl 10.0.0.67它确实显示了这条线。然而,curl如何知道进入哪个目录呢?我没有指定它应该显式地转到/tmp/web内容。
发布于 2022-01-17 13:57:53
只是对@P的阐述.回答.
。
volumes:
- name: web-content
emptyDir: {}init-con上的/tmp/web-content/位置,该容器正在用init-con编写check this out。 initContainers:
- name: init-con
image: busybox:1.31.0
command: ['sh', '-c' ,"echo 'check this out' > /tmp/web-content/index.html"]
volumeMounts:
- name: web-content
mountPath: /tmp/web-content/index.html的web-content卷被挂载为/usr/share/nginx/html目录,因此index.html位置将被视为/usr/share/nginx/html/index.html。(默认登陆页为nginx ),用于容器nginx,因此当您卷曲到容器nginx时,它会显示check this out。 containers:
- image: nginx:1.17.3-alpine
name: nginx
volumeMounts:
- name: web-content
mountPath: /usr/share/nginx/html发布于 2022-01-17 13:41:20
这是因为mountPath
根指令指示硬盘驱动器上的实际路径,即/usr/share/nginx/html,该虚拟主机的资产(HTML、图像、CSS等)位于其中。当要求Nginx显示目录时,索引设置告诉Nginx要提供哪些文件
当您将curl缩到默认端口80时,curl将为您提供html目录的返回内容。。
https://stackoverflow.com/questions/70742176
复制相似问题