Is there any way to run kubectl proxy
, giving it a command as input, and shutting it down when the response is received?
I'm imagining something with the -u
(unix socket) flag, like this:
kubectl proxy -u - < $(echo "GET /api/v1/namespaces/default")
I don't think it's possible, but maybe my socket fu just isn't strong enough.
kubectl proxy
won't give you any way to run a one-off request and terminate the proxy.
Generic way to start a command in the background, run a command and terminate the initially started command finally would be to write a bash script like:
#!/usr/bin/env bash
set -eu
kubectl proxy &
proxy_pid=$!
echo $proxy_pid
until curl -fsSL http://localhost:8001/ > /dev/null; do
echo "waiting for kubectl proxy" >&2
sleep 5
# TODO add max retries so you can break out of this
done
curl http://localhost:8001/api/v1/namespaces/default
function cleanup {
echo "killing kubectl proxy" >&2
kill $proxy_pid
}
trap cleanup EXIT
If you actually want to use sockets:
kubectl proxy -u ./foo.sock
curl --unix-socket ./foo.sock http:/api/v1/namespaces/default
etc.You don't need a long-running kubectl proxy
for this.
Try this:
kubectl get --raw=/api/v1/namespaces/default