Working with storage

Persistent storage keeps data available between restarts of odo.

Adding storage to the application components

Use the odo storage command to add persistent data to your application. Examples of data that must persist include database files, dependencies, and build artifacts, such as a .m2 Maven directory.

Procedure

  1. Add the storage to your component:

    1. $ odo storage create <storage_name> --path=<path_to_the_directory> --size=<size>
  2. Push the storage to the cluster:

    1. $ odo push
  3. Verify that the storage is now attached to your component by listing all storage in the component:

    1. $ odo storage list

    Example output

    1. The component 'nodejs' has the following storage attached:
    2. NAME SIZE PATH STATE
    3. mystorage 1Gi /data Pushed
  4. Delete the storage from your component:

    1. $ odo storage delete <storage_name>
  5. List all storage to verify that the storage state is Locally Deleted:

    1. $ odo storage list

    Example output

    1. The component 'nodejs' has the following storage attached:
    2. NAME SIZE PATH STATE
    3. mystorage 1Gi /data Locally Deleted
  6. Push the changes to the cluster:

    1. $ odo push

Adding storage to a specific container

If your devfile has multiple containers, you can use the --container flag to specify the container you want to attach storage to.

Procedure

  1. Create a devfile with multiple containers:

    1. components:
    2. - name: runtime (1)
    3. container:
    4. image: registry.access.redhat.com/ubi8/nodejs-12:1-36
    5. memoryLimit: 1024Mi
    6. endpoints:
    7. - name: "3000-tcp"
    8. targetPort: 3000
    9. mountSources: true
    10. - name: funtime (2)
    11. container:
    12. image: registry.access.redhat.com/ubi8/nodejs-12:1-36
    13. memoryLimit: 1024Mi
    1The runtime container.
    2The funtime container.
  2. To create storage for the runtime container:

    1. $ odo storage create store --path /data --size 1Gi --container runtime

    Output of the command:

    1. Added storage store to nodejs-testing-xnfg
    2. Please use `odo push` command to make the storage accessible to the component
  3. Verify that the storage is now attached to your component by listing all storage in the component:

    1. $ odo storage list

    Example output

    1. The component 'nodejs-testing-xnfg' has the following storage attached:
    2. NAME SIZE PATH CONTAINER STATE
    3. store 1Gi /data runtime Not Pushed
  4. Push the changes to the cluster:

    1. $ odo push

Switching between ephemeral and persistent storage

You can switch between ephemeral and persistent storage in your project by using the odo preference command. odo preference modifies the global preference in your cluster.

When persistent storage is enabled, the cluster stores the information between the restarts.

When ephemeral storage is enabled, the cluster does not store the information between the restarts.

Ephemeral storage is enabled by default.

Procedure

  1. See the preference currently set in your project:

    1. $ odo preference view

    Example output

    1. PARAMETER CURRENT_VALUE
    2. UpdateNotification
    3. NamePrefix
    4. Timeout
    5. BuildTimeout
    6. PushTimeout
    7. Experimental
    8. PushTarget
    9. Ephemeral true
  2. To unset the ephemeral storage and set the persistent storage:

    1. $ odo preference set Ephemeral false
  3. To set the ephemeral storage again:

    1. $ odo preference set Ephemeral true

    The odo preference command changes the global settings of all your currently deployed components as well as ones you will deploy in future.

  4. Run odo push to make odo create a specified storage for your component:

    1. $ odo push

Additional resources