Setting Up Single-Node Storage

Setting Up Single-Node Storage

The following steps describe how to set up storage when configuring a single-node cluster. Storage is configured using the hostPath option.
  1. Create a data directory:
    sudo mkdir -p /data/volumes
  2. Enable hostPath storage:
    sudo microk8s enable hostpath-storage
  3. Wait for the storage driver to be ready:
    sudo microk8s.kubectl wait deployment -n kube-system -l k8s-app=hostpath-provisioner --for condition=Available=True --timeout=180s
  4. Create custom storage classes.
    # Create an unreplicated storage class sudo microk8s.kubectl apply -f - <<EOF --- kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: unreplicated provisioner: microk8s.io/hostpath reclaimPolicy: Delete parameters: pvDir: /data/volumes volumeBindingMode: WaitForFirstConsumer EOF
    # Create a replicated storage class (same as unreplicated for single node) sudo microk8s.kubectl apply -f - <<EOF --- kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: replicated provisioner: microk8s.io/hostpath reclaimPolicy: Delete parameters: pvDir: /data/volumes volumeBindingMode: WaitForFirstConsumer EOF
    In the single-node instance, both unreplicated and replicated storage classes point to the same hostPath provisioner. This is because replication is not possible with the hostPath provisioner on a single node.
  5. Set up the default storage class:
    sudo microk8s.kubectl patch storageclass unreplicated -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'