简体   繁体   English

将容器中的文件夹公开为 Kubernetes Pod 中的卷

[英]Expose folder from a container as a volume in a Kubernetes Pod

I have a pod which contains two containers.我有一个包含两个容器的 pod。 One container is a web application and another store some static data for this web application.一个容器是 web 应用程序,另一个容器存储此 web 应用程序的一些 static 数据。

The data here is a set of files which are stored in the folder of this container with name /data and that's only function of the container to store this data and expose them to the web application.此处的数据是一组文件,它们存储在此容器的文件夹中,名称为/data ,并且仅容器的 function 用于存储此数据并将它们公开给 web 应用程序。

I'm looking for the way to share the content of this folder with web application container in this pod.我正在寻找与此 pod 中的 web 应用程序容器共享此文件夹内容的方法。

If I'm using the YAML spec below the folder in both containers is empty.如果我使用 YAML 规范,则两个容器中的文件夹下方都是空的。 Is there a way to share the data from container folder without cleaning it up?有没有办法在不清理容器文件夹的情况下共享数据?

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  labels:
    app: my-app
    version: 1.2.3
spec:
  volumes:
    - name: my-app-data-volume

  containers:
    - name: my-app-server
      image: my-app-server-container-name
      volumeMounts:
        - name: my-app-data-volume
          mountPath: /data
      ports:
        - containerPort: 8080

    - name: my-app-data
      image: my-app-data-container-name
      volumeMounts:
        - name: my-app-data-volume
          mountPath: /data

You can use an EmptyDir volume for this.您可以为此使用EmptyDir卷。 Specify the container that contains the files as an initContainer , then copy the files into the EmptyDir volume.将包含文件的容器指定为 initContainer ,然后将文件复制到initContainer卷中。 Finally, mount that volume in the web app container.最后,将该卷安装在 web 应用程序容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Azure容器服务将Kubernetes pod公开到公共Internet - How to expose the Kubernetes pod to the public internet using Azure container service 如何从使用 KubernetesPodOperator 触发它的 Airflow 主机将卷挂载到运行 docker 容器的 Kubernetes Pod - How to mount a volume to a Kubernetes Pod running a docker container from the Airflow host that triggers it using the KubernetesPodOperator 如何将卷附加到 kube.netes pod 容器,如 docker? - How to attache a volume to kubernetes pod container like in docker? 试图将端点从 kubernetes pod 暴露到互联网/浏览器/API - Trying to expose an endpoint from a kubernetes pod to the internet/ browser/ API 从kubernetes容器中复制文件 - Copying files from a kubernetes pod container 在 Kubernetes 的 pod 中从另一个容器启动一个容器 - Start a container from another one in a pod in Kubernetes 无法将卷装入 kube.netes 中的 pod - Unable to mount a volume into a pod in kubernetes 无法从 pod 容器内访问 kubernetes api - Not able to access kubernetes api from inside a pod container Kubernetes Pod没有将卷绑定到容器 - Kubernetes pod not binding volumes to container Kubernetes部署,Pod和容器概念 - Kubernetes Deployments, Pod and Container concepts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM