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) | |
|---|---|---|
| Lifetime | The instance | Independent of instances and deployments |
| Shared between replicas | No, one per instance | Only by instances on the same node (ReadWriteOnce) |
| Use | Scratch space, temporary files | State 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-dataat/var/orders, Persistent,5Gi: the claim is created with the default storage class of the cluster;scratchat/tmp/orders, Volatile, for temporary files.
Apply changes restarts the integration without rebuilding its image.
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:
- 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/ordersare still there, those under/tmp/ordersare gone.
Next: build from Git.