Configuring storage classes

To configure Che to use a configured infrastructure storage, install Che using storage classes. This is especially useful when a user wants to bind a persistent volume provided by a non-default provisioner. To do so, a user binds this storage for the Che data saving and sets the parameters for that storage. These parameters can determine the following:

  • A special host path

  • A storage capacity

  • A volume mod

  • Mount options

  • A file system

  • An access mode

  • A storage type

  • And many others

Che has two components that require persistent volumes to store data:

  • A PostgreSQL database.

  • A Che workspaces. Che workspaces store source code using volumes, for example /projects volume.

Che workspaces source code is stored in the persistent volume only if a workspace is not ephemeral.

Persistent volume claims facts:
  • Che does not create persistent volumes in the infrastructure.

  • Che uses persistent volume claims (PVC) to mount persistent volumes.

  • The Che server creates persistent volume claims.

    A user defines a storage class name in the Che configuration to use the storage classes feature in the Che PVC. With storage classes, a user configures infrastructure storage in a flexible way with additional storage parameters. It is also possible to bind a static provisioned persistent volumes to the Che PVC using the class name.

Procedure

Use CheCluster Custom Resource definition to define storage classes:

  1. Define storage class names: configure the CheCluster Custom Resource, and install Che. See Using chectl to configure the CheCluster Custom Resource during installation.

    spec:
      components:
        database:
          pvc:
            # keep blank unless you need to use a non default storage class for PostgreSQL PVC
            storageClass: 'postgres-storage'
      devEnvironments:
        storage:
          pvc:
            # keep blank unless you need to use a non default storage class for workspace PVC(s)
            storageClass: 'workspace-storage'
  2. Define the persistent volume for a PostgreSQL database in a che-postgres-pv.yaml file:

    che-postgres-pv.yaml file
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: postgres-pv-volume
      labels:
        type: local
    spec:
      storageClassName: postgres-storage
      capacity:
        storage: 1Gi
      accessModes:
        - ReadWriteOnce
      hostPath:
        path: "/data/che/postgres"
  3. Define the persistent volume for a Che workspace in a che-postgres-pv.yaml file:

    che-workspace-pv.yaml file
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: workspace-pv-volume
      labels:
        type: local
    spec:
      storageClassName: workspace-storage
      capacity:
        storage: 10Gi
      accessModes:
        - ReadWriteOnce
      hostPath:
        path: "/data/che/workspace"
  4. Bind the two persistent volumes:

    $ kubectl apply -f che-workspace-pv.yaml -f che-postgres-pv.yaml

You must provide valid file permissions for volumes. You can do it using storage class configuration or manually. To manually define permissions, define storageClass#mountOptions uid and gid. PostgreSQL volume requires uid=26 and gid=26.