Skip to main content

How to delay delete mount pod

note

This feature requires JuiceFS CSI Driver version 0.13.0 and above.

JuiceFS CSI driver deletes mount pod immediately when no application pod is using it. But at some point you may want the mount pod to be deleted lazily. If there are new application pods using the same volume in a short period of time, it is expected that the mount pod will not be destroyed and rebuilt, causing unnecessary waste of resources.

This document shows how to set the delay deletion duration for mount pods.

Static provisioning

You can configure the length of time of delay deletion in PV. Set juicefs/mount-delete-delay in volumeAttributes, the value is the duration to be set. As follows:

apiVersion: v1
kind: PersistentVolume
metadata:
name: juicefs-pv
labels:
juicefs-name: ten-pb-fs
spec:
capacity:
storage: 10Pi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
csi:
driver: csi.juicefs.com
volumeHandle: juicefs-pv
fsType: juicefs
nodePublishSecretRef:
name: juicefs-secret
namespace: default
volumeAttributes:
juicefs/mount-delete-delay: 1m

Where, the unit can be: "ns" (nanoseconds), "us" (microseconds), "ms" (milliseconds), "s" (seconds), "m" (minutes), "h" (hours).

When the last application pod is deleted, the mount pod is marked with the juicefs-delete-at annotation to record the moment when it should be deleted. When the deletion time is reached, the mount pod will be deleted. When a new application Pod uses the same JuiceFS Volume, the annotation juicefs-delete-at will be deleted.

Apply PVC and sample pod as follows:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: juicefs-pvc
namespace: default
spec:
accessModes:
- ReadWriteMany
volumeMode: Filesystem
storageClassName: ""
resources:
requests:
storage: 10Pi
selector:
matchLabels:
juicefs-name: ten-pb-fs
---
apiVersion: v1
kind: Pod
metadata:
name: juicefs-app-mount-options
namespace: default
spec:
containers:
- args:
- -c
- while true; do echo $(date -u) >> /data/out.txt; sleep 5; done
command:
- /bin/sh
image: centos
name: app
volumeMounts:
- mountPath: /data
name: data
resources:
requests:
cpu: 10m
volumes:
- name: data
persistentVolumeClaim:
claimName: juicefs-pvc

Dynamic provisioning

You can configure the length of time of delay deletion in StorageClass. Set juicefs/mount-delete-delay in parameters, the value is the duration to be set. As follows:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: juicefs-sc
namespace: default
provisioner: csi.juicefs.com
parameters:
csi.storage.k8s.io/provisioner-secret-name: juicefs-secret
csi.storage.k8s.io/provisioner-secret-namespace: default
csi.storage.k8s.io/node-publish-secret-name: juicefs-secret
csi.storage.k8s.io/node-publish-secret-namespace: default
juicefs/mount-delete-delay: 1m

Apply PVC and sample pod as follows:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: juicefs-pvc
namespace: default
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Pi
storageClassName: juicefs-sc
---
apiVersion: v1
kind: Pod
metadata:
name: juicefs-app-mount-options
namespace: default
spec:
containers:
- args:
- -c
- while true; do echo $(date -u) >> /data/out.txt; sleep 5; done
command:
- /bin/sh
image: centos
name: app
volumeMounts:
- mountPath: /data
name: juicefs-pv
volumes:
- name: juicefs-pv
persistentVolumeClaim:
claimName: juicefs-pvc