Created
May 19, 2022 18:57
-
-
Save tym-xqo/c50751acd2557f2fbf96354faa026a6f to your computer and use it in GitHub Desktop.
zsh script to run a k8s pod with latest `jackknife` image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/zsh | |
TOKEN=$(python3 -c "import secrets; print(secrets.token_hex(24)[:7])") | |
# echo $TOKEN | |
POD=$(kubectl get pods | grep tmp-$USER-dba | awk '{print $1}') | |
if [[ -z $POD ]] | |
then | |
POD="tmp-$USER-dba-$TOKEN" | |
kubectl run $POD \ | |
--image=registry.gitlab.com/tym27/jackknife:latest \ | |
--env="PGUSER=wmxdbuser" \ | |
--command -- tail -f /dev/null | |
sleep 5 | |
while [[ $(kubectl get pods $POD -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod" && sleep 5; done | |
kubectl cp ${HOME}/.pgpass $POD:/var/lib/postgresql/ | |
else | |
echo "Found $POD, attempting to exec into it...." | |
fi | |
kubectl exec -it $POD -- zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment