【发布时间】:2019-11-25 10:49:36
【问题描述】:
我在一个 pod 中有 2 个容器。 1.网络应用 2.Nginx 我想与 nginx 容器共享来自 Webapp 容器 /var/www/webapp/ 的数据。 /var/www/html
/var/www/webapp ( folder structure )
│ index.php
│
│
└───folder1
│ │ service1.php
│ │
│ └───subfolder1
│ │ app.php
│
└───folder2
│ service2.php
文件夹已正确挂载,但所有文件均丢失。
apiVersion: apps/v1
kind: Deployment
spec:
volumes:
- name: webapp-data
persistentVolumeClaim:
claimName: webapp-data
containers:
- name: webapp
image: webapp
imagePullPolicy: Always
volumeMounts:
- name: webapp-data
mountPath: /var/www/webapp/
- name: nginx
imagePullPolicy: Always
image: nginx
volumeMounts:
- name: webapp-data
mountPath: /var/www/html/
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: webapp-data
spec:
storageClassName: local
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
在 docker 下挂载卷时,容器内的所有文件夹和文件都可用,但在 k8s 中不可用。
【问题讨论】:
-
blinger-main是什么?因为它肯定不是那个 pod 中的卷。 -
在 pod 上运行的容器可以共享卷和网络,因为它们可以在 localhost 上相互访问。对于您的用例,您需要确保两个容器的 volumeMounts 名称相同才能访问相同的卷。
-
我的错误,只是在这里提供时输入错误。
标签: kubernetes persistent-volumes kubernetes-pvc