挂载path中的单个节点本地kubernetes持续卷文件正从容器中删除

我正尝试在主机重新启动时保留一个容器/容器的状态。

我尝试了以下步骤: PV-Link

我在主机上创build了这个目录: mkdir -p /root/sample-data

在这个目录下创build一个文件: echo 'Hello from Kubernetes storage' > /root/sample-data/a.txt

我从这个文件创build了卷,索赔和pod:

kubectl create -f ./sample-pod.yml

 persistentvolume "task-pv-volume" created persistentvolumeclaim "task-pv-claim" created pod "sample-pod" created 

sample-pod.yaml文件的内容:

 --- kind: PersistentVolume apiVersion: v1 metadata: name: task-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: "/root/sample-data" --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: task-pv-claim spec: storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 10Gi --- apiVersion: v1 kind: Pod metadata: name: sample-pod labels: app: sample-pod spec: volumes: - name: task-pv-storage persistentVolumeClaim: claimName: task-pv-claim containers: - name: sample-pod image: some-image:61 command: ["/bin/bash"] stdin: true tty: true volumeMounts: - mountPath: "/opt/ABC" name: task-pv-storage 

运行这个命令后,我能够在容器中的/opt/ABC目录中看到a.txt文件。 我也可以在主机的/root/sample-data目录中看到/opt/ABC所有子目录。

但是,容器和主机的/root/sample-data目录中缺less/opt/ABC子目录中的所有文件。

有没有人有一个想法,我要去哪里错了?

Interesting Posts