-
Notifications
You must be signed in to change notification settings - Fork 1
/
kube-load.sh
56 lines (47 loc) · 1.17 KB
/
kube-load.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Load input data to a Persistent Volume on a Kubernetes cluster.
# parse command-line arguments
if [[ $# != 2 ]]; then
echo "usage: $0 <pvc-name> <local-path> <pvc-path>"
exit -1
fi
PVC_NAME="$1"
PVC_PATH="$2"
POD_FILE="pod.yaml"
POD_NAME="${USER}-load-$(printf %04x ${RANDOM})"
LOCAL_PATH="$(realpath $2)"
# create pod config file
cat > ${POD_FILE} <<EOF
apiVersion: v1
kind: Pod
metadata:
name: ${POD_NAME}
spec:
containers:
- name: ${POD_NAME}
image: ubuntu
args: ["sleep", "infinity"]
volumeMounts:
- mountPath: /workspace
name: ${PVC_NAME}
restartPolicy: Never
volumes:
- name: ${PVC_NAME}
persistentVolumeClaim:
claimName: ${PVC_NAME}
EOF
# create pod
kubectl create -f ${POD_FILE}
# wait for pod to initialize
POD_STATUS=""
while [[ ${POD_STATUS} != "Running" ]]; do
sleep 2
POD_STATUS="$(kubectl get pod --no-headers --output jsonpath={.status.phase} ${POD_NAME})"
done
# copy input data to pod
echo "copying data..."
kubectl exec ${POD_NAME} -- bash -c "mkdir -p ${PVC_PATH}"
kubectl cp "${LOCAL_PATH}" "${POD_NAME}:${PVC_PATH}/$(basename ${LOCAL_PATH})"
# delete pod
kubectl delete -f ${POD_FILE}
rm -f ${POD_FILE}