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
Where are stored docker volumes Windows? Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).
A persistent volume is a piece of storage in a cluster that an administrator has provisioned. It is a resource in the cluster, just as a node is a cluster resource.
Docker also supports containers storing files in-memory on the host machine. Such files are not persisted. If you're running Docker on Linux, tmpfs mount is used to store files in the host's system memory. If you're running Docker on Windows, named pipe is used to store files in the host's system memory.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With