Creating a hostPath PersistentVolume

Create a hostPath PersistentVolume.

A hostPath volume mounts a file or directory from the host node's file system into your pod. For more information about hostPath volume, see Types of Volumes Opens in a new tab.

A hostPath PersistentVolume must be used only in a single-node cluster. Kubernetes does not support hostPath on a multi-node cluster currently.

You can create a hostPath PersistentVolume by using the management console.

To view a list of persistent volumes in your IBM® Cloud Private cluster, from the navigation menu, click Platform > Storage.

Required user type or access level: Cluster administrator

Creating a hostPath PersistentVolume by using the Create PersistentVolume dialog box

To create a hostPath PersistentVolume:

  1. From the navigation menu, click Platform > Storage.
  2. Click Create PersistentVolume.
  3. Enter the PersistentVolume details.

    To create a hostPath PersistentVolume, specify the following parameters:

    General tab

    • Name - (required) Provide a name for the PersistentVolume.
    • Capacity - (required) Provide the storage capacity.
    • Access mode - (optional) Select ReadWriteOnce
    • Reclaim policy - (optional) Select Retain or Recycle.
    • Storage Type - (required) Select Host path.

      Label tab

      Attach a label to the PersistentVolume. A label is a key and value pair. For example: type=local. This parameter is optional.

      Parameters tab

    • Parameters for storage. Parameters are supplied as key and value pairs. For hostPath, you must specify:
      • A path
        • Key: - path
        • Value: - the location of the file or directory on your cluster's node. For example: /tmp/data
  4. Click Create.

Creating a hostPath PersistentVolume by using the "Create resource" window

  1. From the dashboard, click Create resource.
  2. Copy and paste a YAML or JSON file into the "Create resource" window. For more information about creating a PersistentVolume by using a YAML file, see Create a PersistentVolume Opens in a new tab.

    A simple YAML might look like this example:

    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: hostpath2
      labels:
        type: local
    spec:
      capacity:
        storage: 1Gi
      accessModes:
        - ReadWriteOnce
      reclaimPolicy:
        - Recycle
      hostPath:
        path: "/tmp/data1"
    
  3. Click Create.

After the deployment completes, a new hostPath PersistentVolume is displayed in the PersistentVolume list. Review the status of the PersistentVolume. The PersistentVolume must have a status of Available.