带有 EKS 集群的 PV 和 PVC

PV & PVC with EKS Cluster

kubectl apply -f pvc.yaml下面的yaml文件之后,我可以在已经创建的容器中找到挂载路径/var/local/pvctest。但是,工作节点中的主机路径/var/local/pvctest没有创建。

我是使用 EKS 的 PV 和 PVC 的新手,非常感谢任何解决此问题的帮助!

kind: Deployment
apiVersion: apps/v1
metadata:
  name: pvctest
  labels:
    alias: pvctest
spec:
  selector:
    matchLabels:
      alias: pvctest
  replicas: 1
  template:
    metadata:
      labels:
        alias: pvctest
    spec:
      containers:
      - name: pvctest
        image: neo4j
        ports:
        - containerPort: 7474
        - containerPort: 7687
        volumeMounts:
        - name: testpv
          mountPath: /var/local/pvctest
      volumes:
      - name: testpv
        persistentVolumeClaim:
          claimName: pvctest-claim
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: pvtest
  labels:
    type: local
spec:
  persistentVolumeReclaimPolicy: Retain
  capacity:
    storage: 3Gi
  accessModes:
  - ReadWriteOnce
  hostPath:
    path: /var/local/pvctest
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvctest-claim
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

                  

具有 hostPath 的 PersistentVolume 要求主机上的目录为 pre-created。如果您希望自动为您创建目录:

...
containers:
- name: pvctest
  image: neo4j
  ...
  volumeMounts:
  - name: testpv
    mountPath: /var/local/pvctest
volumes:
- name: testpv
  hostPath:
    path: /data
    type: DirectoryOrCreate

PV/PVC 实际上是 hostPath 的可选选项。