Skip to content

Commit c6d37cf

Browse files
authored
Adding ability to mount CSI volumes in privildeged shell (#64)
Signed-off-by: Bernard Gütermann <[email protected]>
1 parent 4884f4b commit c6d37cf

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,51 @@ nsenter -t 2152 -n
8989
```
9090

9191
*You need to be able to start privileged containers for that.*
92+
93+
## Mounting External CSI Volumes
94+
95+
You can mount volumes from your CSI storage layer using the `-m` flag. This allows you to move data to/from node devices seamlessly. The PVC will be mounted at `/opt-pvc`. This is useful for failover in minimal systems that do not have a built in shell (eg. Talos).
96+
Here is an example of how you can retrieve zfs/lvm data from a volume on a failed CSI node and put it back in your distributed storage layer:
97+
98+
```bash
99+
k node-shell -n <namespace> -x <node_with_data> -m <pvc_name>
100+
101+
# install rsync
102+
apk add rsync
103+
104+
# Add lvm/zfs libs
105+
# ZFS
106+
mount -o bind /host/dev /dev
107+
mount -o bind /host/usr/local /usr/local
108+
touch /lib/libuuid.so.1
109+
mount -o bind /host/lib/libuuid.so.1 /lib/libuuid.so.1
110+
touch /lib/libuuid.so.1.3.0
111+
mount -o bind /host/lib/libuuid.so.1.3.0 /lib/libuuid.so.1.3.0
112+
touch /lib/libblkid.so.1
113+
mount -o bind /host/lib/libblkid.so.1 /lib/libblkid.so.1
114+
touch /lib/libblkid.so.1.1.0
115+
mount -o bind /host/lib/libblkid.so.1.1.0 /lib/libblkid.so.1.1.0
116+
#LVM
117+
touch /usr/lib/libaio.so.1
118+
mount -o bind /host/usr/lib/libaio.so.1.0.2 /usr/lib/libaio.so.1
119+
touch /usr/lib/libudev.so.1
120+
mount -o bind /host/usr/lib/libudev.so.1 /usr/lib/libudev.so.1
121+
export PATH=$PATH:/host/sbin
122+
mkdir /lib/modules
123+
mount -o bind /host/lib/modules /lib/modules
124+
125+
# look for data to recover
126+
zfs list
127+
NAME USED AVAIL REFER MOUNTPOINT
128+
hdd-1 15.9T 7.52T 96K /hdd-1
129+
hdd-1/SOME-OLD-PVC-FROM-PREVIOUS-NODE-INSTALL 361G 7.52T 361G - -
130+
131+
# mount the failed volume
132+
zfs set mountpoint=/mnt hdd-1/SOME-OLD-PVC-FROM-PREVIOUS-NODE-INSTALL
133+
zfs mount /hdd-1/SOME-OLD-PVC-FROM-PREVIOUS-NODE-INSTALL
134+
135+
# recover the data : copy it to the mounted CSI volume
136+
rsync -avh --info=progress2 /mnt/ /opt-pvc/
137+
```
138+
139+
the above exemple assumes `pvc_name` already exists in `namespace`. *You need to be able to start privileged containers.*

kubectl-node_shell

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,16 @@ while [ $# -gt 0 ]; do
6666
kubectl="$kubectl --namespace=${key##*=}"
6767
shift
6868
;;
69+
-m | --mount)
70+
volumes=$(echo "$volumes" | jq '. += [{"persistentVolumeClaim": {"claimName": "'"$2"'", "type": ""}, "name": "'"pvc"'"}]')
71+
volume_mounts=$(echo "$volume_mounts" | jq '. += [{"mountPath": "/opt-pvc", "name": "'"pvc"'"}]')
72+
shift
73+
shift
74+
;;
6975
-x)
7076
x_mode=1
71-
volumes='[{"hostPath":{"path":"/","type":""},"name":"host-root"}]'
72-
volume_mounts='[{"mountPath":"/host","name":"host-root"}]'
77+
volumes=$(echo "$volumes" | jq '. += [{"hostPath": {"path": "/", "type": ""}, "name": "host-root"}]')
78+
volume_mounts=$(echo "$volume_mounts" | jq '. += [{"mountPath":"/host","name":"host-root"}]')
7379
shift
7480
;;
7581
--image)

0 commit comments

Comments
 (0)