【发布时间】:2020-07-20 14:18:55
【问题描述】:
tl;dr:我们如何将 pod 中的现有目录挂载到 PV,从而使我们能够持久保存将要生成的数据?
我们目前正在运行 K8s 1.16.7,集成了 Azure Disk 和 Azure File。我们有一个图像,其中包含一些我们希望存储在 PV 上以保持持久性的目录。在 Docker 中,这很容易处理,因为容器会将数据写入主机挂载。有谁知道如何在 Kubernetes 中解决这个问题?当我们现在这样做时,容器会启动,但目录(例如:/etc/nginx/conf.d/ 作为 PV 的挂载)是空的,并且 Pod 崩溃了。
例子:
在下面的容器中,/usr/src/app 填充了 hello-world 应用程序。部署下面的文件后,容器由于无法在 /usr/src/app 中找到任何内容而崩溃(由于 PV 挂载,目录为空)。
---
apiVersion: v1
kind: Namespace
metadata:
name: testwebsite
labels:
environment: development
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: normal
namespace: testwebsite
provisioner: disk.csi.azure.com
parameters:
storageaccounttype: Standard_LRS
kind: Managed
resourceGroup: resourcegroup
cachingmode: None
mountOptions:
- dir_mode=0777
- file_mode=0777
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-azurefile
namespace: testwebsite
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: normal
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
namespace: testwebsite
spec:
replicas: 1
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.8
ports:
- containerPort: 8080
volumeMounts:
- name: azurefile01
mountPath: "/usr/src/app"
volumes:
- name: azurefile01
persistentVolumeClaim:
claimName: pvc-azurefile
目标:将容器内 /usr/src/app 中的数据写入 PV。
提前谢谢!
【问题讨论】:
标签: kubernetes storage persistent-volumes