| title | description | tags | dates | ||||
|---|---|---|---|---|---|---|---|
Using Kubernetes subPath with Scaleway File Storage on Kapsule clusters |
This page explains how to use the Kubernetes `subPath` feature with Scaleway File Storage on Kapsule |
kubernetes storage filestorage file storage |
|
import Requirements from '@macros/iam/requirements.mdx'
Scaleway File Storage (SFS) is a managed shared filesystem that supports ReadWriteMany (RWX) access mode. When used with Kapsule through the Scaleway File Storage CSI driver, PersistentVolumes can be provisioned dynamically using PersistentVolumeClaims (PVCs).
This guide explains how to use Kubernetes subPath to mount different subdirectories of a single SFS volume into separate container paths. This allows you to logically partition storage between workloads without creating multiple volumes.
Common use cases include (but are not limited to):
- Separating application data and logs within a shared filesystem
- Allowing multiple containers to mount isolated directories from the same PVC
- Organizing multi-service deployments that share a single storage backend
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- Created a Kubernetes Kapsule cluster
- Installed the Kubernetes command-line tool
kubectl - Added the tag
scw-filestorage-csito your Kubernetes Kapsule cluster - Access to the Scaleway File Storage API
-
Create a file named
pvc.yaml:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: shared-fs-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 100G ## volume size - edit towards your requirements storageClassName: scw-fs
-
Apply it to your cluster using
kubectl:kubectl apply -f pvc.yaml
The Scaleway CSI driver automatically provisions a File Storage volume.
You can mount different subdirectories of the same PVC using subPath.
-
Create an example
deployment.yaml:apiVersion: apps/v1 kind: Deployment metadata: name: demo-app spec: replicas: 1 selector: matchLabels: app: demo template: metadata: labels: app: demo spec: containers: - name: web image: nginx volumeMounts: - name: shared-data mountPath: /var/www/html subPath: html - name: shared-data mountPath: /var/log/nginx subPath: logs volumes: - name: shared-data persistentVolumeClaim: claimName: shared-fs-pvc
-
Apply it using
kubectl:kubectl apply -f deployment.yaml
The Deployment mounts:
/var/www/htmlas subdirectoryhtmlinside the PVC/var/log/nginxas subdirectorylogsinside the PVC
To control directory ownership, you can:
- Pre-create directories using an initContainer
chownthem in an initContainer- Run your main container as a user who already has access
Example initContainer:
initContainers:
- name: init-permissions
image: busybox
command: ["sh", "-c", "mkdir -p /data/html /data/logs && chown -R 1000:1000 /data"]
volumeMounts:
- name: shared-data
mountPath: /dataA common pattern is to have multiple containers inside the same Pod, each mounting a different directory of the same Scaleway File Storage PVC. This allows shared storage while keeping each component's data logically separated.
Example: We have two web + worker containers sharing one PVC using different subPath values.
apiVersion: v1
kind: Pod
metadata:
name: multi-container-demo
spec:
containers:
- name: web
image: nginx
volumeMounts:
- name: shared-data
mountPath: /usr/share/nginx/html
subPath: frontend
- name: worker
image: busybox
command: ["sh", "-c", "while true; do echo 'worker running' >> /data/logs/worker.log; sleep 5; done"]
volumeMounts:
- name: shared-data
mountPath: /data/logs
subPath: worker-logs
volumes:
- name: shared-data
persistentVolumeClaim:
claimName: shared-fs-pvcApply the configuration using kubectl apply -f pod.yaml.
- The web container serves files from the
frontenddirectory on the PVC. - The worker container writes logs into the
worker-logsdirectory.
Both containers use the same File Storage volume, but their data stays cleanly separated.
If you want to ensure directories exist with correct permissions, add an initContainers to your configuration:
```yaml
initContainers:
- name: init-folders
image: busybox
command: ["sh", "-c", "mkdir -p /data/frontend /data/worker-logs && chmod -R 755 /data"]
volumeMounts:
- name: shared-data
mountPath: /data
```
Remove the deployment:
kubectl delete -f deployment.yamlRemove the PVC:
kubectl delete -f pvc.yamlThis will delete the Scaleway File Storage volume as well.
For more information on the Kubernetes `subPath` feature, refer to the official [Kubernetes storage documentation](https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath).