Skip to main content

6. Attach Persistent Storage

The file system of an instance is lost with it. A route that keeps files (an idempotent repository, a staging directory, a download cache) needs a volume.

Volatile versus persistent storage​

Two kinds of storage can be mounted in an integration. They differ in how long the data lives.

Volatile (emptyDir)Persistent (PersistentVolumeClaim)
LifetimeThe instanceIndependent of instances and deployments
Shared between replicasNo, one per instanceOnly by instances on the same node (ReadWriteOnce)
UseScratch space, temporary filesState that must survive a restart

Mount them (Storage)​

On orders-api, choose Add Capability, then Storage, a tab of the overview.

In Storages, add:

  • orders-data at /var/orders, Persistent, 5Gi: the claim is created with the default storage class of the cluster;
  • scratch at /tmp/orders, Volatile, for temporary files.

Apply changes restarts the integration without rebuilding its image.

The mount path is yours to choose

Routes refer to the path, not to the storage. Use the same path in every environment so that the route does not change between them.

Use the volume from a route​

A file-based idempotent repository on the volume keeps the keys already processed across restarts:

orders.camel.yaml
- beans:
- name: processedOrders
type: org.apache.camel.support.processor.idempotent.FileIdempotentRepository
properties:
fileStore: /var/orders/processed.dat
- route:
id: orders-import
from:
uri: file:/var/orders/inbox
parameters:
move: ../done
steps:
- idempotentConsumer:
header: CamelFileName
idempotentRepository: processedOrders
steps:
- log: "Importing ${header.CamelFileName}"

Replicas and access modes​

A persistent storage is mounted read-write by one node at a time (ReadWriteOnce): it cannot back several replicas spread over nodes. With more than one replica, keep the state outside the integration, in a database or an object store.

Verification​

  • Restart the integration: the files under /var/orders are still there, those under /tmp/orders are gone.

Next: build from Git.