Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
Last active January 23, 2024 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbkrkr/0da65863799bbe415576afb78b74fde3 to your computer and use it in GitHub Desktop.
Save thbkrkr/0da65863799bbe415576afb78b74fde3 to your computer and use it in GitHub Desktop.
curl Elasticsearch clusters managed by ECK - eckurl ns1/es1 /_cat/health
#!/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