首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这个卷曲要从k8s吊舱内的容器中取出?

为什么这个卷曲要从k8s吊舱内的容器中取出?
EN

Stack Overflow用户
提问于 2022-01-17 13:29:56
回答 2查看 240关注 0票数 1

此部署创建了一个在其中包含init容器的pod。容器将卷装载到tmp/web-content中,并将单行“签出”写入index.html。

代码语言:javascript
复制
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

我启动临时吊舱,以检查我是否可以看到这一行“检查这”使用卷曲。

代码语言:javascript
复制
k run tmp --restart=Never --rm -i --image=nginx:alpine -- curl 10.0.0.67

它确实显示了这条线。然而,curl如何知道进入哪个目录呢?我没有指定它应该显式地转到/tmp/web内容。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-01-17 13:57:53

只是对@P的阐述.回答.

  • 下面创建了一个公共存储空间,其名称为"web-content"

代码语言:javascript
复制
     ​volumes:
     ​- name: web-content
       ​emptyDir: {}

  • web内容安装在init容器init-con上的/tmp/web-content/位置,该容器正在用init-con编写check this out

代码语言:javascript
复制
      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.htmlweb-content卷被挂载为/usr/share/nginx/html目录,因此index.html位置将被视为/usr/share/nginx/html/index.html。(默认登陆页为nginx ),用于容器nginx,因此当您卷曲到容器nginx时,它会显示check this out

代码语言:javascript
复制
      containers:
      - image: nginx:1.17.3-alpine
        name: nginx
        volumeMounts:
        - name: web-content
          mountPath: /usr/share/nginx/html
票数 1
EN

Stack Overflow用户

发布于 2022-01-17 13:41:20

这是因为mountPath

根指令指示硬盘驱动器上的实际路径,即/usr/share/nginx/html,该虚拟主机的资产(HTML、图像、CSS等)位于其中。当要求Nginx显示目录时,索引设置告诉Nginx要提供哪些文件

当您将curl缩到默认端口80时,curl将为您提供html目录的返回内容。。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70742176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档