58 lines
2.2 KiB
YAML
58 lines
2.2 KiB
YAML
apiVersion: storage.k8s.io/v1
|
|
kind: StorageClass
|
|
metadata:
|
|
name: local-path
|
|
annotations:
|
|
storageclass.kubernetes.io/is-default-class: "true"
|
|
provisioner: rancher.io/local-path
|
|
volumeBindingMode: WaitForFirstConsumer
|
|
reclaimPolicy: Delete
|
|
---
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: local-path-config
|
|
namespace: kube-system
|
|
data:
|
|
config.json: |-
|
|
{
|
|
"nodePathMap":[
|
|
{
|
|
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
|
|
"paths":["/var/lib/rancher/k3s/storage"]
|
|
}
|
|
]
|
|
}
|
|
# The Setup script runs when a PVC is created
|
|
setup: |-
|
|
#!/bin/sh
|
|
set -eu
|
|
|
|
# Variables provided by the provisioner:
|
|
# $VOL_DIR = The ugly UUID path (e.g., .../pvc-1234-abcd)
|
|
# $PVC_NAMESPACE = The namespace (e.g., databases)
|
|
# $PVC_NAME = The PVC name (e.g., main-db-1)
|
|
|
|
# 1. Define your pretty path in /data/pvc for easier management
|
|
PRETTY_PATH="/data/pvc/${PVC_NAMESPACE}/${PVC_NAME}"
|
|
|
|
# 2. Create the pretty folder
|
|
mkdir -p "$PRETTY_PATH"
|
|
chmod 777 "$PRETTY_PATH"
|
|
|
|
# 3. Create a symlink: Ugly UUID -> Pretty Path
|
|
# Kubernetes looks at the UUID path, but data is actually written to Pretty Path
|
|
ln -s "$PRETTY_PATH" "$VOL_DIR"
|
|
# The Teardown script runs when a PVC is deleted
|
|
teardown: "#!/bin/sh\nset -eu\n\n# Variables provided: $VOL_DIR (The UUID path)\n\n# 1. Resolve where the symlink points to (The pretty path)\nif [ -L \"$VOL_DIR\" ]; then\n PRETTY_PATH=$(readlink \"$VOL_DIR\")\n \n # 2. Remove the Symlink (The UUID entry)\n rm \"$VOL_DIR\"\n \n # 3. Remove the actual data (The pretty folder)\n # Note: We verify it is inside /data/pvc to prevent accidents\n case \"$PRETTY_PATH\" in\n /data/pvc/*)\n rm -rf \"$PRETTY_PATH\"\n # Try to remove empty parent directories\n dir=$(dirname \"$PRETTY_PATH\")\n rmdir \"$dir\" 2>/dev/null || true\n rmdir \"$(dirname \"$dir\")\" 2>/dev/null || true\n ;;\n *)\n echo \"Warning: PRETTY_PATH $PRETTY_PATH is not in /data/pvc, skipping deletion\"\n ;;\n esac\nfi"
|
|
helperPod.yaml: |-
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: helper-pod
|
|
spec:
|
|
containers:
|
|
- name: helper-pod
|
|
image: busybox
|
|
imagePullPolicy: IfNotPresent
|