Changing Microk8s’ default hostpath addon storage location
- less than 1 minute read
- 4 code samples in Shell and YAML
Also available in Română
Hello everyone,
This is a short guide on how to change Microk8s’ default storage path for the hostpath addon.
First, ensure the addon is enabled:
microk8s enable hostpath-storageChanging the StorageClass affects newly provisioned volumes; it does not move existing persistent volume data. Back up and migrate existing data separately.
Then create a new directory in which you want to store volumes created in the Microk8s instance.
mkdir -p /var/microk8s-volumesThen create and apply the storage class yaml file:
kind: StorageClassapiVersion: storage.k8s.io/v1metadata: name: custom-storageclassprovisioner: microk8s.io/hostpathreclaimPolicy: Retainparameters: pvDir: /var/microk8s-volumesvolumeBindingMode: WaitForFirstConsumerTo change the default storage class for Microk8s you need to run these commands:
kubectl patch storageclass microk8s-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'kubectl patch storageclass custom-storageclass -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'Thank you for reading!