So... after searching different solutions on the web I believe that this is the best way to do this, There is a Github Issue in order to implement PersistentVolume fuse mounts later, but we don't know when this will be possible.
Basically the solution on the link describes a workaround where we use the kubernetes lifecycle events postStart and preStop to do the mount and unmount for us.
The first step is to be sure that you have the gcsfuse binary installed in our container.
The way to do this is first create the gcsfuse.repo file.
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
After then in your docker file:
COPY gcsfuse.repo /etc/yum.repos.d/
RUN dnf -y install gcsfuse
RUN mkdir -p /etc/letsencrypt
In order to perform the mount command on kubernetes, we need to run the pod as --privileged, and add the capability SYS_ADMIN
spec:
...
template:
...
spec:
...
containers:
- name: my-container
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
lifecycle:
postStart:
exec:
command: ["gcsfuse", "-o", "nonempty", "your-bucket-name", "/etc/letsencrypt"]
preStop:
exec:
command: ["fusermount", "-u", "/etc/letsencrypt"]
To set the authentication you just need to ensure your GKE cluster is created with the OAuth scope https://www.googleapis.com/auth/devstorage.read_write, and everything else will be handled automatically.
Your GCS storage will be mounted in all instances of your pod, as ReadWriteMany, shared storage via fuse but you have to keep in mind that this solution will be slow while writing to the buckets.