I'd like to access and edit files in my Kubernetes PersistentVolume on my local computer (macOS), but I cannot understand where to find those files!
I'm pointing my hostPath
to /tmp/wordpress-volume
but I cannot find it anywhere. What is the hidden secret I'm missing
I'm using the following configuration on a docker-for-desktop cluster Version 2.0.0.2 (30215)
.
kind: PersistentVolume
metadata:
name: wordpress-volume
spec:
# ...
hostPath:
path: /tmp/wordpress-volume
kind: PersistentVolumeClaim
metadata:
name: wordpress-volume-claim
# ...
kind: Deployment
metadata:
name: wordpress
# ...
spec:
containers:
- image: wordpress:4.8-apache
# ...
volumeMounts:
- name: wordpress-volume
mountPath: /var/www/html
volumes:
- name: wordpress-volume
persistentVolumeClaim:
claimName: wordpress-volume-claim
Thanks to @aman-tuladhar and some hours lost on the internet I've found out that you just need to make sure storageClassName
is set for you PersistentVolume and PersistentVolumeClaim.
As per documentation if you want to avoid that Kubernetes dynamically generetes PersistentVolumes without considering the one you statically declared, you can just set a empty string " "
.
In my case I've set storageClassName: manual
.
kind: PersistentVolume
metadata:
name: wordpress-volume
spec:
# ...
storageClassName: manual
hostPath:
path: /tmp/wordpress-volume
kind: PersistentVolumeClaim
metadata:
name: wordpress-volume-claim
spec:
storageClassName: manual
# ...
This works out of the box with docker-for-desktop
cluster (as long as mountPath
is set to a absolute path).
References: