| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 1 | # local-path-provisioner v0.0.37, based on upstream deploy/local-path-storage.yaml |
| 2 | # with these local changes: |
| 3 | # - PVs live under /var/k8s; setup.sh/teardown.sh create and unmount one |
| 4 | # ZFS dataset per PV (rpool/var/k8s/<pv>) in the host mount namespace. |
| 5 | # - The helper pod needs hostPID and privileged for nsenter. |
| 6 | # - The namespace (PSA enforce=privileged) is not managed here. |
| 7 | # setup and teardown below must stay in sync with setup.sh and teardown.sh. |
| 8 | # The provisioner reads helperPod.yaml only at startup; restart it after |
| 9 | # changing that. |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 10 | apiVersion: apps/v1 |
| 11 | kind: Deployment |
| 12 | metadata: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 13 | name: local-path-provisioner |
| 14 | namespace: local-path-storage |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 15 | labels: |
| 16 | app: local-path-provisioner |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 17 | spec: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 18 | replicas: 1 |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 19 | selector: |
| 20 | matchLabels: |
| 21 | app: local-path-provisioner |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 22 | template: |
| 23 | metadata: |
| 24 | labels: |
| 25 | app: local-path-provisioner |
| 26 | spec: |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 27 | serviceAccountName: local-path-provisioner-service-account |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 28 | containers: |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 29 | - name: local-path-provisioner |
| 30 | image: docker.io/rancher/local-path-provisioner:v0.0.37 |
| 31 | imagePullPolicy: IfNotPresent |
| 32 | command: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 33 | - local-path-provisioner |
| 34 | - --debug |
| 35 | - start |
| 36 | - --config |
| 37 | - /etc/config/config.json |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 38 | # The helper pod needs hostPID for nsenter (see setup.sh). |
| 39 | - --allow-unsafe-helper-pod-template |
| 40 | ports: |
| 41 | - name: health |
| 42 | containerPort: 8080 |
| 43 | protocol: TCP |
| 44 | startupProbe: |
| 45 | httpGet: |
| 46 | path: /health |
| 47 | port: health |
| 48 | initialDelaySeconds: 5 |
| 49 | periodSeconds: 5 |
| 50 | failureThreshold: 12 |
| 51 | livenessProbe: |
| 52 | httpGet: |
| 53 | path: /health |
| 54 | port: health |
| 55 | initialDelaySeconds: 10 |
| 56 | periodSeconds: 10 |
| 57 | readinessProbe: |
| 58 | httpGet: |
| 59 | path: /ready |
| 60 | port: health |
| 61 | initialDelaySeconds: 5 |
| 62 | periodSeconds: 5 |
| 63 | volumeMounts: |
| 64 | - name: config-volume |
| 65 | mountPath: /etc/config/ |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 66 | env: |
| 67 | - name: POD_NAMESPACE |
| 68 | valueFrom: |
| 69 | fieldRef: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 70 | fieldPath: metadata.namespace |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 71 | - name: CONFIG_MOUNT_PATH |
| 72 | value: /etc/config/ |
| 73 | - name: HEALTH_PORT |
| 74 | value: "8080" |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 75 | volumes: |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 76 | - name: config-volume |
| 77 | configMap: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 78 | name: local-path-config |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 79 | --- |
| 80 | apiVersion: v1 |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 81 | kind: ConfigMap |
| 82 | metadata: |
| 83 | name: local-path-config |
| 84 | namespace: local-path-storage |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 85 | data: |
| 86 | config.json: |- |
| 87 | { |
| 88 | "nodePathMap":[ |
| 89 | { |
| 90 | "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES", |
| 91 | "paths":["/var/k8s"] |
| 92 | } |
| 93 | ] |
| 94 | } |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 95 | setup: | |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 96 | #!/bin/sh |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 97 | # Creates a ZFS dataset per PV. The helper pod runs with hostPID, and all |
| 98 | # ZFS and filesystem operations are performed in the host's mount namespace |
| 99 | # (nsenter -t 1 -m). Running zfs directly inside the helper container would |
| 100 | # mount the dataset only inside the container's own mount namespace; the |
| 101 | # workload would then write into the parent dataset, and the child dataset |
| 102 | # would shadow that data after the next host reboot. |
| 103 | # |
| 104 | # The provisioner passes the volume path as $VOL_DIR (v0.0.2x and later); |
| 105 | # older versions passed it as -p. |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 106 | set -eu |
| 107 | |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 108 | absolutePath=${VOL_DIR:-} |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 109 | while getopts "m:s:p:" opt |
| 110 | do |
| 111 | case $opt in |
| 112 | p) |
| 113 | absolutePath=$OPTARG |
| 114 | ;; |
| 115 | s) |
| 116 | sizeInBytes=$OPTARG |
| 117 | ;; |
| 118 | m) |
| 119 | volMode=$OPTARG |
| 120 | ;; |
| 121 | esac |
| 122 | done |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 123 | [ -n "$absolutePath" ] || { echo "setup: no volume path given" >&2; exit 1; } |
| 124 | |
| 125 | host() { nsenter -t 1 -m -- "$@"; } |
| 126 | |
| 127 | host zfs create "rpool${absolutePath}" |
| 128 | host zfs mount "rpool${absolutePath}" 2>/dev/null || : |
| 129 | host findmnt -n -o SOURCE "${absolutePath}" | grep -qx "rpool${absolutePath}" |
| 130 | host chmod 0777 "${absolutePath}" |
| 131 | teardown: | |
| 132 | #!/bin/sh |
| 133 | # Unmounts (but keeps) the PV's ZFS dataset. Runs in the host's mount |
| 134 | # namespace; see setup.sh. |
| 135 | set -eu |
| 136 | |
| 137 | absolutePath=${VOL_DIR:-} |
| 138 | while getopts "m:s:p:" opt |
| 139 | do |
| 140 | case $opt in |
| 141 | p) |
| 142 | absolutePath=$OPTARG |
| 143 | ;; |
| 144 | s) |
| 145 | sizeInBytes=$OPTARG |
| 146 | ;; |
| 147 | m) |
| 148 | volMode=$OPTARG |
| 149 | ;; |
| 150 | esac |
| 151 | done |
| 152 | [ -n "$absolutePath" ] || { echo "teardown: no volume path given" >&2; exit 1; } |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 153 | |
| 154 | nsenter -t 1 -m -- zfs set mountpoint=none "rpool${absolutePath}" |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 155 | helperPod.yaml: | |
| 156 | apiVersion: v1 |
| 157 | kind: Pod |
| 158 | metadata: |
| 159 | name: helper-pod |
| 160 | spec: |
| 161 | priorityClassName: system-node-critical |
| 162 | tolerations: |
| 163 | - key: node.kubernetes.io/disk-pressure |
| 164 | operator: Exists |
| 165 | effect: NoSchedule |
| 166 | hostPID: true |
| 167 | containers: |
| 168 | - name: helper-pod |
| 169 | image: alpine:3.20 |
| 170 | imagePullPolicy: IfNotPresent |
| 171 | securityContext: |
| 172 | privileged: true |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 173 | --- |
| 174 | apiVersion: v1 |
| 175 | kind: ServiceAccount |
| 176 | metadata: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 177 | name: local-path-provisioner-service-account |
| 178 | namespace: local-path-storage |
| 179 | --- |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 180 | # Since v0.0.24 helper pods run in the provisioner's namespace. |
| 181 | apiVersion: rbac.authorization.k8s.io/v1 |
| 182 | kind: Role |
| 183 | metadata: |
| 184 | name: local-path-provisioner-role |
| 185 | namespace: local-path-storage |
| 186 | rules: |
| 187 | - apiGroups: [""] |
| 188 | resources: ["pods"] |
| 189 | verbs: ["get", "list", "watch", "create", "patch", "update", "delete"] |
| 190 | --- |
| 191 | apiVersion: rbac.authorization.k8s.io/v1 |
| 192 | kind: RoleBinding |
| 193 | metadata: |
| 194 | name: local-path-provisioner-bind |
| 195 | namespace: local-path-storage |
| 196 | roleRef: |
| 197 | apiGroup: rbac.authorization.k8s.io |
| 198 | kind: Role |
| 199 | name: local-path-provisioner-role |
| 200 | subjects: |
| 201 | - kind: ServiceAccount |
| 202 | name: local-path-provisioner-service-account |
| 203 | namespace: local-path-storage |
| 204 | --- |
| 205 | # Leftover from PodSecurityPolicy times (psp:default no longer grants anything). |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 206 | apiVersion: rbac.authorization.k8s.io/v1 |
| 207 | kind: RoleBinding |
| 208 | metadata: |
| 209 | name: local-path-provisioner:psp:default |
| 210 | namespace: local-path-storage |
| 211 | roleRef: |
| 212 | apiGroup: rbac.authorization.k8s.io |
| 213 | kind: ClusterRole |
| 214 | name: psp:default |
| 215 | subjects: |
| 216 | - kind: ServiceAccount |
| 217 | name: local-path-provisioner-service-account |
| 218 | namespace: local-path-storage |
| 219 | --- |
| 220 | apiVersion: rbac.authorization.k8s.io/v1 |
| 221 | kind: ClusterRole |
| 222 | metadata: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 223 | name: local-path-provisioner-role |
| 224 | rules: |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 225 | - apiGroups: [""] |
| 226 | resources: ["nodes", "persistentvolumeclaims", "configmaps", "pods", "pods/log"] |
| 227 | verbs: ["get", "list", "watch"] |
| 228 | - apiGroups: [""] |
| 229 | resources: ["persistentvolumes"] |
| 230 | verbs: ["get", "list", "watch", "create", "patch", "update", "delete"] |
| 231 | - apiGroups: [""] |
| 232 | resources: ["events"] |
| 233 | verbs: ["create", "patch"] |
| 234 | - apiGroups: ["storage.k8s.io"] |
| 235 | resources: ["storageclasses"] |
| 236 | verbs: ["get", "list", "watch"] |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 237 | --- |
| 238 | apiVersion: rbac.authorization.k8s.io/v1 |
| 239 | kind: ClusterRoleBinding |
| 240 | metadata: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 241 | name: local-path-provisioner-bind |
| 242 | roleRef: |
| 243 | apiGroup: rbac.authorization.k8s.io |
| 244 | kind: ClusterRole |
| 245 | name: local-path-provisioner-role |
| 246 | subjects: |
| 247 | - kind: ServiceAccount |
| 248 | name: local-path-provisioner-service-account |
| 249 | namespace: local-path-storage |
| 250 | --- |
| 251 | apiVersion: storage.k8s.io/v1 |
| 252 | kind: StorageClass |
| 253 | metadata: |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 254 | name: local-path |
| 255 | provisioner: rancher.io/local-path |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 256 | volumeBindingMode: WaitForFirstConsumer |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 257 | reclaimPolicy: Delete |