我正在为 CKAD 学习,我正在尝试在我的本地 minikube 集群上创建一个 PersistenVolume
类型的 hostPath
并挂载到一个容器
步骤如下:
hostPath
和 path: "/data/vol1/"
类型的 PVBound
minikube ssh
并创建了一个文件 /data/vol1/foo.bar
foo.bar
,但它不在那里。这是yaml文件
apiVersion: v1
kind: PersistentVolume
metadata:
name: 1311-pv
spec:
capacity:
storage: 2Gi
hostPath:
path: "/data/vol1/"
accessModes:
- ReadWriteMany
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: 1311-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: ex10
spec:
volumes:
- name: pvc
persistentVolumeClaim:
claimName: 1311-pvc
containers:
- image: httpd
name: web
volumeMounts:
- mountPath: "/var/something/"
name: pvc
这是系统的状态:
k get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
1311-pvc Bound pvc-c892f798-8ee6-4040-9177-3e77327e9ec6 1Gi RWX standard 5m
k get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
1311-pv 2Gi RWX Retain Available 13m
pvc-c892f798-8ee6-4040-9177-3e77327e9ec6 1Gi RWX Delete Bound default/1311-pvc standard 13m
pod describe ex10
...
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-lw45q (ro)
/var/something/ from pvc (rw)
....
一切看起来都正确,但我没有看到容器内的文件:
k exec ex10 -- ls /var/something
- no results here -
我在 minikube vm 中创建的:
ssh minikube
$ ls /data/vol1/
foo.bar
答案 0 :(得分:1)
我找到了解决此问题的方法,PV 必须指定 storageClassName: standard
才能工作。
这就是 PV 将数据正确存储到 minikube 主机的样子
apiVersion: v1
kind: PersistentVolume
metadata:
name: 1311-pv
spec:
storageClassName: "standard"
capacity:
storage: 2Gi
hostPath:
path: "/host/"
accessModes:
- ReadWriteMany