#!/bin/bash set -e usage () { echo "usage: $0 tag disk_filename" exit 1 } [[ $# -eq 2 ]] || usage tag="$1" disk_filename="$2" cd "$(dirname $0)" [[ -f "$disk_filename" && -r "$disk_filename" ]] || { echo "$disk_filename does not exist, is not a regular file, or is not readable"; exit 1; } [[ "$disk_filename" == *.xz ]] || { echo "$disk_filename does not appear to be an xz-compressed disk image"; exit 1; } sed "s!!${tag}!" ./k8s/deployment.yaml.template > ./k8s/deployment.yaml echo "Creating PVC..." kubectl apply -f ./k8s/pvc.yaml echo "Creating temporary pod..." kubectl apply -f ./k8s/pod-tmp.yaml echo "Waiting for temporary pod..." while ! kubectl get pod pdp-tmp|grep -q Running; do sleep 1; done echo "Checking for disk image..." if ! kubectl exec -it pdp-tmp -- test -f /mnt/rq0.dsk &>/dev/null; then echo "Uploading compressed disk image..." kubectl exec pdp-tmp -- rm -f /mnt/rq0.dsk.xz kubectl cp "$disk_filename" pdp-tmp:/mnt/rq0.dsk.xz echo "Extracting disk image..." kubectl exec pdp-tmp -- apk add xz kubectl exec pdp-tmp -- xz -d /mnt/rq0.dsk.xz fi echo "Removing temporary pod..." kubectl delete -f ./k8s/pod-tmp.yaml echo "Creating PDP deployment..." kubectl apply -f ./k8s/deployment.yaml echo "Creating services..." for i in ./k8s/svc-*.yaml; do kubectl apply -f "$i"; done echo "Done! Optionally, run ./k8s/configure-metallb.sh to put the services on an external IP."