Chapter 12. Using Persistent Storage in Fuse on OpenShift


Fuse on OpenShift 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-formatted 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.

12.1. About Volumes and Volume Types

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.

12.2. About 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 Configuring Persistent Storage for creating various types of PersistentVolumes.

12.3. Configuring Persistent Volume

You can provision a Persistent Volume by creating a configuration file. This storage then can be accessed by creating a PersistentVolume Claim.

Procedure

  1. Create a configuration file named pv.yaml using the sample configuration below. This provisions a path on the host machine as a PersistentVolume named pv001.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv0001
    spec:
      accessModes:
        - ReadWriteOnce
      capacity:
        storage: 2Mi
      hostPath:
        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.

  2. Create the PersistentVolume.

    oc create -f pv.yaml
  3. Verify the creation of PersistentVolume. This will list all the PersistentVolumes configured in your OpenShift cluster:

    oc get pv

12.4. Creating 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.

Procedure

  • 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
    metadata:
      name: pvc0001
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Mi

12.5. Using Persistent Volumes in Pods

Pods use Volume Mounts to define the filesystem mount location and Volumes to define reference PersistentVolumeClaims.

Procedure

  1. Create a sample container configuration as shown below which mounts PersistentVolumeClaim pvc0001 at /usr/share/data in its filesystem.

    spec:
      template:
        spec:
          containers:
            - volumeMounts:
              - name: vol0001
                mountPath: /usr/share/data
          volumes:
            - name: vol0001
              persistentVolumeClaim:
                claimName: pvc0001

    Any data written by the application to the directory /usr/share/data is now persisted across container restarts.

  2. Add this configuration in the file src/main/fabric8/deployment.yml in a Fuse on OpenShift application and create OpenShift resources using command:

    mvn fabric8:resource-apply
  3. Verify that the created DeploymentConfiguration has the volume mount and the volume.

    oc describe deploymentconfig <application-dc-name>

    For Fuse on OpenShift quickstarts, replace the <application-dc-name> with the Maven project name, for example spring-boot-camel.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.