I'm studying for the CKAD and I'm trying to create a PersistenVolume
of type hostPath
on my local minikube cluster and mount to a container
These are the steps:
hostPath
and path: "/data/vol1/"
Bound
minikube ssh
and created a file /data/vol1/foo.bar
foo.bar
under the folder /var/something/` of the container, but it's not there.This is the yaml file
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
And this is the status of the system:
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)
....
Everything looks correct to be, but I don't see the file inside the container:
k exec ex10 -- ls /var/something
- no results here -
that I created into the minikube vm:
ssh minikube
$ ls /data/vol1/
foo.bar
I found a solution for this issue, the PV must specify the storageClassName: standard
in order to work.
This is how the PV should look like to properly store data into minikube host
apiVersion: v1
kind: PersistentVolume
metadata:
name: 1311-pv
spec:
storageClassName: "standard"
capacity:
storage: 2Gi
hostPath:
path: "/host/"
accessModes:
- ReadWriteMany