Small PVs and Kadalu Storage

Posted on Feb 11, 2020 by Aravinda Vishwanathapura
3 minutes read.

Kadalu Storage can provision the smallest Persistent Volume as low as 20MiB for the applications running in Kubernetes(k8s). Small PVs are attractive for many use cases like providing home dir for each container user or storing config files of applications etc.

Performant Read and write of small files over the network are always challenging, and it is still hard to match local filesystem performance.

This blog is to discuss a hybrid approach to solve these performance issues if the data is not very critical(In case of failure, it is okay to lose last 10-30 seconds data).

Claim PV from Kadalu as usual with the required size, for example, 200MiB.

kind: PersistentVolumeClaim
apiVersion: v1
  name: pv1
  storageClassName: kadalu.replica1
    - ReadWriteMany
      storage: 200Mi

Prepare the Pod container image such that, on start, it copies data from /srcdata to $HOME directory. The idea is to mount Kadalu PV to /src directory and design application to use $HOME directory(Or any other required directory). With this approach, the application will be using local data instead of accessing data from the PV provided by Kadalu.

On Pod termination(using pre stop hook), call the reverse sync script to sync data from $HOME to /srcdata. This method secures the Pod/container data in PV So that it can be started again anytime.

apiVersion: v1
kind: Pod
  name: pod1
    app: my-super-app
  - name: my-super-app
    imagePullPolicy: IfNotPresent
          command: ["/usr/local/bin/", "~/", "/srcdata"]
    - mountPath: "/srcdata"
      name: csivol
  - name: csivol
      claimName: pv1
  restartPolicy: OnFailure

Note: The container image used in the above example is non-existent. It is used for illustrative purposes only.

Minimize the Risk

What happens in cases where the Pod terminates abruptly or, the node goes down without being able to call Pre to stop the hook script? Let’s create a background job that syncs data from $HOME to /srcdata at regular intervals. For example, if the background job runs once every 10 seconds, then the risk of losing data is reduced to 10 seconds(plus sync time).

Any failure to sync data from $HOME to /srcdata(or vice-versa) should be treated as a Pod failure to avoid more data loss.

Note: This approach is not suitable for large volumes, but a similar technique can be adapted for medium and large volumes if Inotify(or similar tools) is available for containers.

Thanks, Gautham Pai(Jnaapti) for brainstorming the issues related to small PVs and data movements required when an application Pod starts in other node and hostPath was used as PV.

WARNING: This approach is not suitable for all use cases. The specific use case creates a trade-off that losing data for such minimal time duration is considered to be acceptable.

Join the Kadalu team as we plan, design and develop new features. We are available on our Slack instance,

Aravinda Vishwanathapura

Kadalu Maintainer

Website| Twitter| Github

© 2022 Kadalu Community( All Rights Reserved.