Skip to content

Instantly share code, notes, and snippets.

@tym-xqo
Created May 19, 2022 18:57
Show Gist options
  • Save tym-xqo/c50751acd2557f2fbf96354faa026a6f to your computer and use it in GitHub Desktop.
Save tym-xqo/c50751acd2557f2fbf96354faa026a6f to your computer and use it in GitHub Desktop.
zsh script to run a k8s pod with latest `jackknife` image
#!/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