Last active
January 23, 2024 09:26
-
-
Save thbkrkr/0da65863799bbe415576afb78b74fde3 to your computer and use it in GitHub Desktop.
curl Elasticsearch clusters managed by ECK - eckurl ns1/es1 /_cat/health
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
#!/bin/bash -eu | |
get-password() { | |
kubectl -n $ns get secret $esName-es-elastic-user -o go-template='{{.data.elastic | base64decode}}' | |
} | |
port-forward-es() { | |
if [[ "${V:-}" == "1" ]]; then | |
echo kubectl -n $ns port-forward "service/$esName-es-http" 9200 | |
fi | |
kubectl -n $ns port-forward "service/$esName-es-http" 9200 > /dev/null | |
} | |
main() { | |
declare ns=default | |
declare esName=$1 && shift | |
declare uri=$1 && shift | |
if [[ "$esName" =~ / ]]; then | |
ns=$(cut -d '/' -f1 <<< $esName) | |
esName=$(cut -d '/' -f2 <<< $esName) | |
fi | |
trap "exit" INT TERM ERR | |
trap "kill 0" EXIT | |
port-forward-es & | |
sleep 1.5 # yolo | |
if [[ "${V:-}" == "1" ]]; then | |
echo curl -sk -u elastic:$(get-password) https://localhost:9200$uri $@ | |
fi | |
curl -sk -u elastic:$(get-password) -H "Content-type: application/json" https://localhost:9200$uri $@ | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment