Skip to content

Deploying local-path-provisioner on k3s for development clusters

Stand up the local-path-provisioner on a k3s cluster — single-binary, no replication, perfect for dev. Includes the full installer and the cases where it must not be used.

You spin up a k3s node on a small VM for a developer environment. The team creates a PVC for the test Postgres, the PVC stays Pending, and someone spends two hours reading CSI documentation before remembering that vanilla k3s ships with a local-path-provisioner — but only on the default storage path, only on the node where the pod runs, and only if you actually enable it on the cluster you bootstrapped. Local-path is the right answer for dev clusters and the wrong answer for anything else, and the distinction is not subtle.

What’s happening

The Rancher local-path-provisioner is a single-binary CSI shim that creates a hostPath volume on whichever node a pod is scheduled to. There is no replication, no snapshot support, no migration between nodes, no quota. When the pod is deleted the directory stays on disk until the PVC is deleted (assuming reclaimPolicy: Delete). When the node fails, the data fails with it.

That’s the right behavior for: a developer’s laptop running k3s, a CI build cluster where every PVC is throwaway, a preview environment that lives for the lifetime of a feature branch, and a single-node staging environment where the operator accepts that “data is the snapshot of the VM.” It is the wrong behavior for: any production workload, any multi-node cluster where pods can move, anything that holds customer data, anything you intend to back up via CSI snapshots. k3s installs a local-path StorageClass by default in recent versions; the installer below removes the default-class flag from it and sets up tiered local paths, which is what makes it usable past day one.

How to verify

Confirm k3s is installed and the provisioner is running:

kubectl get pods -n kube-system | grep local-path
# local-path-provisioner-5b5f5fb84d-xxxxx   1/1   Running

Check the default StorageClass:

kubectl get storageclass
# NAME                   PROVISIONER             RECLAIMPOLICY
# local-path (default)   rancher.io/local-path   Delete

Create a test PVC and watch where the data lands:

cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: probe-local
spec:
  accessModes: [ReadWriteOnce]
  storageClassName: local-path
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: probe-pod
spec:
  containers:
    - name: shell
      image: busybox:latest
      command: ["sh", "-c", "echo hello > /data/hello && sleep 3600"]
      volumeMounts:
        - mountPath: /data
          name: data
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: probe-local
EOF

# Once the pod is Running, see where on the node the data actually lives
kubectl get pv $(kubectl get pvc probe-local -o jsonpath='{.spec.volumeName}') -o yaml \
  | yq '.spec.local.path, .spec.nodeAffinity'

The path is a real directory on the node’s filesystem. That’s the data plane — back up that directory or you don’t back up the PVC.

The fix

Save the script as /root/setup-local-path.sh and run it on the k3s server node. It installs k3s with the embedded provisioner disabled, deploys the upstream local-path-provisioner from Rancher with multiple paths mapped to different disks for dev tiering, sets the default StorageClass policy, adds a quota-style annotation hint, and configures a node-prep step so each path is on the disk you want.

#!/usr/bin/env bash
set -euo pipefail

### k3s + local-path-provisioner installer for dev clusters
### Run on the k3s server node as root.
### NOT for production. Single-node data plane. No replication.

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT IF NEEDED ===
K3S_VERSION="v1.30.4+k3s1"
LOCAL_PATH_VERSION="v0.0.27"
NVME_PATH="/var/lib/rancher/k3s/storage/local-path-nvme"
SSD_PATH="/var/lib/rancher/k3s/storage/local-path-ssd"
HDD_PATH="/mnt/hdd/local-path"
# =====================

echo
echo "========================================"
echo "k3s + local-path-provisioner"
echo "========================================"
echo

echo "==> Updating base OS and prerequisites"
if command -v dnf >/dev/null 2>&1; then
  dnf -y update
  dnf -y install curl tar gzip ca-certificates jq iproute net-tools
elif command -v apt-get >/dev/null 2>&1; then
  apt-get update -y
  apt-get install -y curl tar gzip ca-certificates jq iproute2 net-tools
fi

echo "==> Preparing local-path directories"
mkdir -p "${NVME_PATH}" "${SSD_PATH}" "${HDD_PATH}"
chmod 700 "${NVME_PATH}" "${SSD_PATH}" "${HDD_PATH}"

echo "==> Installing k3s with default local-storage DISABLED"
# We disable the bundled provisioner so we can install the upstream one with our config
curl -sfL https://get.k3s.io | \
  INSTALL_K3S_VERSION="${K3S_VERSION}" \
  INSTALL_K3S_EXEC="server --disable=local-storage --disable=traefik --write-kubeconfig-mode 644" \
  sh -

systemctl is-active --quiet k3s || systemctl start k3s

export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

echo "==> Waiting for node to be Ready"
for i in {1..60}; do
  if kubectl get nodes 2>/dev/null | grep -q " Ready "; then break; fi
  sleep 2
done

echo "==> Deploying local-path-provisioner ${LOCAL_PATH_VERSION}"
kubectl apply -f "https://raw.githubusercontent.com/rancher/local-path-provisioner/${LOCAL_PATH_VERSION}/deploy/local-path-storage.yaml"

echo "==> Custom configmap with three named paths"
cat > /tmp/local-path-config.yaml <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
  name: local-path-config
  namespace: local-path-storage
data:
  config.json: |
    {
      "nodePathMap": [
        {
          "node": "DEFAULT_PATH_FOR_NON_LISTED_NODES",
          "paths": ["${SSD_PATH}"]
        }
      ],
      "sharedFileSystemPath": ""
    }
  setup: |
    #!/bin/sh
    set -eu
    mkdir -m 0777 -p "\$VOL_DIR"
  teardown: |
    #!/bin/sh
    set -eu
    rm -rf "\$VOL_DIR"
  helperPod.yaml: |
    apiVersion: v1
    kind: Pod
    metadata:
      name: helper-pod
    spec:
      priorityClassName: system-node-critical
      tolerations:
        - key: node.kubernetes.io/disk-pressure
          operator: Exists
          effect: NoSchedule
      containers:
        - name: helper-pod
          image: busybox
          imagePullPolicy: IfNotPresent
EOF
kubectl apply -f /tmp/local-path-config.yaml

echo "==> StorageClasses for dev tiers"
cat > /tmp/local-path-storageclasses.yaml <<EOF
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-nvme
  annotations:
    storageclass.kubernetes.io/is-default-class: "false"
    stackharbor.com/note: "Dev only. No replication. Tied to node."
provisioner: rancher.io/local-path
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
parameters:
  nodePath: "${NVME_PATH}"
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-ssd
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
    stackharbor.com/note: "Dev only. Default class for dev clusters."
provisioner: rancher.io/local-path
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
parameters:
  nodePath: "${SSD_PATH}"
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-hdd
  annotations:
    storageclass.kubernetes.io/is-default-class: "false"
    stackharbor.com/note: "Dev only. Cold storage for build artifacts."
provisioner: rancher.io/local-path
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
parameters:
  nodePath: "${HDD_PATH}"
EOF
kubectl apply -f /tmp/local-path-storageclasses.yaml

echo "==> Restarting local-path-provisioner to pick up new config"
kubectl -n local-path-storage rollout restart deploy/local-path-provisioner
kubectl -n local-path-storage rollout status deploy/local-path-provisioner --timeout=180s

echo "==> Smoke test: 1Gi PVC on each tier"
for sc in local-nvme local-ssd local-hdd; do
  cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: probe-${sc}
  namespace: default
spec:
  accessModes: [ReadWriteOnce]
  storageClassName: ${sc}
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: probe-${sc}-pod
  namespace: default
spec:
  restartPolicy: Never
  containers:
    - name: shell
      image: busybox:latest
      command: ["sh", "-c", "dd if=/dev/zero of=/data/test bs=1M count=64 && sync && ls -la /data/"]
      volumeMounts:
        - mountPath: /data
          name: data
  volumes:
    - name: data
      persistentVolumeClaim:
        claimName: probe-${sc}
EOF
done

echo "==> Waiting for probe pods to complete (max 120s)"
for sc in local-nvme local-ssd local-hdd; do
  kubectl wait --for=condition=Ready pod/probe-${sc}-pod -n default --timeout=120s || true
done

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Cluster info:"
kubectl get nodes -o wide
echo
echo "StorageClasses:"
kubectl get storageclass
echo
echo "Probe PVCs:"
kubectl get pvc -n default | grep probe-
echo
echo "Probe pods:"
kubectl get pods -n default | grep probe-
echo
echo "Clean up probes when done:"
echo "kubectl delete pvc,pod -n default -l app=probe || kubectl get pvc,pod -n default | grep probe- | awk '{print \$1}' | xargs -r kubectl delete -n default"
echo
echo "Reminder: this cluster has no replication. Snapshot the VM nightly."

Make it executable and run:

chmod 700 /root/setup-local-path.sh
/root/setup-local-path.sh

When NOT to use local-path-provisioner: production clusters of any size, multi-node clusters where workloads should survive a node loss, anything that holds customer data, anything you intend to clone/restore via CSI snapshots (local-path has no snapshot driver — its “snapshot” is your VM-level snapshot of the underlying disk), and shared-storage workloads requiring ReadWriteMany. If you find yourself reaching for local-path in production because “it works on dev,” what you actually want is Longhorn, Rook-Ceph, OpenEBS Mayastor, or your cloud provider’s CSI — see the StorageClass tiering KB for that path.

Operationally on dev: rotate the node’s VM-level snapshots nightly, treat the local-path directory as ephemeral, and never let it cross 80% disk usage because there is no eviction policy that protects you from disk-pressure taints. A k3s node at 95% disk usage will start evicting pods, including the system pods, and you discover the cluster is broken by trying to debug it.

Stack Harbor runs dev and CI Kubernetes fleets under Managed Cloud Ops — including k3s for preview environments, with VM-level snapshot rotation and dev-data lifecycle baked in. If you need preview clusters that spin up and down without manual intervention, talk to deployment management.