> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siderolabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Storage

> Using local storage for Kubernetes workloads.

Using local storage for Kubernetes workloads implies that the pod will be bound to the node where the local storage is available.
Local storage is not replicated, so in case of a machine failure contents of the local storage will be lost.

## User volumes

The simplest way to use local storage is to use [ user volumes](https://docs.siderolabs.com/talos/v1.14/configure-your-talos-cluster/storage-and-disk-management/disk-management/user.md).

Once the user volume is created, it is automatically mounted under `/var/mnt/<user-volume-name>` path on the node.

For example, create a configuration patch for a user volume named `local-storage`:

```yaml local-storage.yaml theme={null}
apiVersion: v1alpha1
kind: UserVolumeConfig
name: local-storage
provisioning:
  diskSelector:
    match: "!system_disk"
  minSize: 2GB
  maxSize: 2GB
```

Apply the patch to the machine configuration:

```bash theme={null} theme={null}
talosctl --nodes <worker-ip> patch mc --patch @local-storage.yaml
```

If you're using Omni, apply this as a cluster config patch instead of running `talosctl` directly, see [Create a patch for cluster machines](https://docs.siderolabs.com/omni/omni-cluster-setup/create-a-patch-for-cluster-machines.md) for the exact steps.

If there is enough space available on a non-system disk (see `diskSelector`), the user volume will be created and mounted under `/var/mnt/local-storage` path on the node.

```bash theme={null}
talosctl -n <worker-ip> get volumestatus u-local-storage
talosctl -n <worker-ip> get mountstatus u-local-storage
```

Now you can use the `/var/mnt/local-storage` path in your Kubernetes manifests to refer to the local storage:

```yaml theme={null}
apiVersion: v1
kind: Pod
metadata:
  name: local-storage-pod
spec:
  containers:
  - name: local-storage-container
    # ...
    volumeMounts:
    - mountPath: /usr/share
      name: local-storage-volume
  volumes:
  - name: local-storage-volume
    hostPath:
      path: /var/mnt/local-storage
      type: DirectoryOrCreate
```

## Local path provisioner

[Local Path Provisioner](https://github.com/rancher/local-path-provisioner) can be used to dynamically provision local storage.

The simplest way to do this is to configure [user volumes](https://docs.siderolabs.com/talos/v1.14/configure-your-talos-cluster/storage-and-disk-management/disk-management/user.md) for Local Path Provisioner to use.

Apply the following machine configuration patch:

> [!NOTE]
>
> Ensure that you have [enough space](https://docs.siderolabs.com/talos/v1.14/configure-your-talos-cluster/storage-and-disk-management/disk-management/layout.md) available to provision the user volume.

```yaml theme={null}
apiVersion: v1alpha1
kind: UserVolumeConfig
name: local-path-provisioner
provisioning:
  diskSelector:
    match: disk.transport == 'nvme'
  minSize: 200GB
  maxSize: 200GB
```

Make sure to update Local Path Provisioner configuration to use the user volume path `/var/mnt/local-path-provisioner` as the root path for the local storage.

For example, Local Path Provisioner can be installed using [kustomize](https://kustomize.io/) with the following configuration:

```yaml kustomization.yaml theme={null}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- github.com/rancher/local-path-provisioner/deploy?ref=v0.0.31
patches:
- patch: |-
    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: local-path-config
      namespace: local-path-storage
    data:
      config.json: |-
        {
                "nodePathMap":[
                {
                        "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
                        "paths":["/var/mnt/local-path-provisioner"]
                }
                ]
        }
- patch: |-
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: local-path
      annotations:
        storageclass.kubernetes.io/is-default-class: "true"
- patch: |-
    apiVersion: v1
    kind: Namespace
    metadata:
      name: local-path-storage
      labels:
        pod-security.kubernetes.io/enforce: privileged
```

Put `kustomization.yaml` into a new directory, and run this command to install Local Path Provisioner to a Talos Linux cluster.

```bash theme={null}
kustomize build | kubectl apply -f -
```

This applies the following changes:

* Change default `/opt/local-path-provisioner` path to `/var/mnt/local-path-provisioner`
* make `local-path` storage class the default storage class (optional)
* label the `local-path-storage` namespace as privileged to allow privileged pods to be scheduled there

To test the Local Path Provisioner, you can refer to the [Usage section of the official guide](https://github.com/rancher/local-path-provisioner?tab=readme-ov-file#usage).

You can check that directories for PVCs are created on the node's filesystem with the `talosctl ls /var/mnt/local-path-provisioner` command.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.