Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 9. Using Persistent Storage in Fuse Integration Services

Fuse Integration Services (FIS) applications are based on OpenShift containers, which do not have a persistent filesystem. Every time you start an application it is started in a new container with an immutable Docker image. Hence any persisted data in the file systems is lost when the container stops. But applications need to store some state as data in a persistent store and sometimes applications share access to a common data store. OpenShift platform supports provisioning of external stores as Persistent Storage.

9.1. Volumes

OpenShift allows pods and containers to mount Volumes as file systems which are backed by multiple host-local or network attached storage endpoints. Volume types include:

  • emptydir (empty directory): This is a default volume type. It is a directory which gets allocated when the pod is created on a local host. It is not copied across the servers and when you delete the pod the directory is removed.
  • configmap: It is a directory with contents populated with key-value pairs from a named configmap.
  • hostPath (host directory): It is a directory with specific path on any host and it requires elevated privileges.
  • secret (mounted secret): Secret volumes mount a named secret to the provided directory.
  • persistentvolumeclaim or pvc (persistent volume claim): This links the volume directory in the container to a persistent volume claim you have allocated by name. A persistent volume claim is a request to allocate storage. Note that if your claim is not bound, your pods will not start.

Volumes are configured at the Pod level and can only directly access an external storage using hostPath. Hence it is harder to mange the access to shared resources for multiple Pods as hostPath volumes.

9.2. PersistentVolumes

PersistentVolumes allow cluster administrators to provision cluster wide storage which is backed by various types of network storage like NFS, Ceph RBD, AWS Elastic Block Store (EBS), etc. PersistentVolumes also specify capacity, access modes, and recycling policies. This allows pods from multiple Projects to access persistent storage without worrying about the nature of the underlying resource.

See the Configuring Persistent Storage for creating various types of PersistentVolumes.

9.3. Sample PersistentVolume configuration

The sample configuration below provisions a path on the host machine as a PersistentVolume named pv001:

apiVersion: v1
kind: PersistentVolume
  name: pv0001
    - ReadWriteOnce
    storage: 2Mi
    path: /data/pv0001/

Here the host path is /data/pv0001 and storage capacity is limited to 2MB. For example, when using OpenShift CDK it will provision the directory /data/pv0001 from the virtual machine hosting the OpenShift Cluster. To create this PersistentVolume, add the above configuration in a file pv.yaml and use the command:

oc create -f pv.yaml

To verify the creation of PersistentVolume, use the following command, which will list all the PersistentVolumes configured in your OpenShift cluster:

oc get pv

9.4. PersistentVolumeClaims

A PersistentVolume exposes a storage endpoint as a named entity in an OpenShift cluster. To access this storage from Projects, PersistentVolumeClaims must be created that can access the PersistentVolume. PersistentVolumeClaims are created for each Project with customized claims for a certain amount of storage with certain access modes.

The sample configuration below creates a claim named pvc0001 for 1MB of storage with read-write-once access against a PersistentVolume named pv0001.

apiVersion: v1
kind: PersistentVolumeClaim
  name: pvc0001
    - ReadWriteOnce
      storage: 1Mi

9.5. Volumes in Pods

Pods use Volume Mounts to define the filesystem mount location and Volumes to define reference PersistentVolumeClaims. The sample container configuration below mounts PersistentVolumeClaim pvc0001 at /usr/share/data in its filesystem.

        - volumeMounts:
          - name: vol0001
            mountPath: /usr/share/data
        - name: vol0001
            claimName: pvc0001

Any data written by the application to the directory /usr/share/data is now persisted across container restarts. Add this configuration in the file src/main/fabric8/deployment.yml in a FIS application and create OpenShift resources using command:

mvn fabric8:resource-apply

To verify that the created DeploymentConfiguration has the volume mount and volume use the command:

oc describe deploymentconfig <application-dc-name>

For FIS quickstarts, the <application-dc-name> is the Maven project name, for example spring-boot-camel.