mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #15394 from JanetKuo/kubectl-proxy-api-prefix
Auto commit by PR queue bot
This commit is contained in:
commit
4c8e6f47ec
@ -51,7 +51,7 @@ The above lets you 'curl localhost:8001/custom/api/v1/pods'
|
|||||||
The IP address on which to serve on.
|
The IP address on which to serve on.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
\fB\-\-api\-prefix\fP="/api/"
|
\fB\-\-api\-prefix\fP="/"
|
||||||
Prefix to serve the proxied API under.
|
Prefix to serve the proxied API under.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
|
@ -80,7 +80,7 @@ $ kubectl proxy --api-prefix=/k8s-api
|
|||||||
--accept-hosts="^localhost$,^127\\.0\\.0\\.1$,^\\[::1\\]$": Regular expression for hosts that the proxy should accept.
|
--accept-hosts="^localhost$,^127\\.0\\.0\\.1$,^\\[::1\\]$": Regular expression for hosts that the proxy should accept.
|
||||||
--accept-paths="^/.*": Regular expression for paths that the proxy should accept.
|
--accept-paths="^/.*": Regular expression for paths that the proxy should accept.
|
||||||
--address="127.0.0.1": The IP address on which to serve on.
|
--address="127.0.0.1": The IP address on which to serve on.
|
||||||
--api-prefix="/api/": Prefix to serve the proxied API under.
|
--api-prefix="/": Prefix to serve the proxied API under.
|
||||||
--disable-filter[=false]: If true, disable request filtering in the proxy. This is dangerous, and can leave you vulnerable to XSRF attacks, when used with an accessible port.
|
--disable-filter[=false]: If true, disable request filtering in the proxy. This is dangerous, and can leave you vulnerable to XSRF attacks, when used with an accessible port.
|
||||||
-p, --port=8001: The port on which to run the proxy. Set to 0 to pick a random port.
|
-p, --port=8001: The port on which to run the proxy. Set to 0 to pick a random port.
|
||||||
--reject-methods="POST,PUT,PATCH": Regular expression for HTTP methods that the proxy should reject.
|
--reject-methods="POST,PUT,PATCH": Regular expression for HTTP methods that the proxy should reject.
|
||||||
|
@ -33,8 +33,7 @@ function stop-proxy()
|
|||||||
PROXY_PORT=
|
PROXY_PORT=
|
||||||
}
|
}
|
||||||
|
|
||||||
# Starts "kubect proxy" to test the client proxy. You may pass options, e.g.
|
# Starts "kubect proxy" to test the client proxy. $1: api_prefix
|
||||||
# --api-prefix.
|
|
||||||
function start-proxy()
|
function start-proxy()
|
||||||
{
|
{
|
||||||
stop-proxy
|
stop-proxy
|
||||||
@ -45,15 +44,21 @@ function start-proxy()
|
|||||||
PROXY_PORT=$(kube::util::get_random_port)
|
PROXY_PORT=$(kube::util::get_random_port)
|
||||||
kube::log::status "On try ${retry}, use proxy port ${PROXY_PORT} if it's free"
|
kube::log::status "On try ${retry}, use proxy port ${PROXY_PORT} if it's free"
|
||||||
if kube::util::test_host_port_free "127.0.0.1" "${PROXY_PORT}"; then
|
if kube::util::test_host_port_free "127.0.0.1" "${PROXY_PORT}"; then
|
||||||
# the --www and --www-prefix are just to make something definitely show up for
|
if [ $# -eq 0 ]; then
|
||||||
# wait_for_url to see.
|
kubectl proxy -p ${PROXY_PORT} --www=. 1>&2 & break
|
||||||
kubectl proxy -p ${PROXY_PORT} --www=. --www-prefix=/healthz "$@" 1>&2 & break
|
else
|
||||||
|
kubectl proxy -p ${PROXY_PORT} --www=. --api-prefix="$1" 1>&2 & break
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
sleep 1;
|
sleep 1;
|
||||||
done
|
done
|
||||||
|
|
||||||
PROXY_PID=$!
|
PROXY_PID=$!
|
||||||
kube::util::wait_for_url "http://127.0.0.1:${PROXY_PORT}/healthz" "kubectl proxy $@"
|
if [ $# -eq 0 ]; then
|
||||||
|
kube::util::wait_for_url "http://127.0.0.1:${PROXY_PORT}/healthz" "kubectl proxy"
|
||||||
|
else
|
||||||
|
kube::util::wait_for_url "http://127.0.0.1:${PROXY_PORT}/$1/healthz" "kubectl proxy --api-prefix=$1"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup()
|
function cleanup()
|
||||||
@ -163,6 +168,7 @@ KUBE_API_VERSIONS="v1,extensions/v1beta1" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver
|
|||||||
--kubelet-port=${KUBELET_PORT} \
|
--kubelet-port=${KUBELET_PORT} \
|
||||||
--runtime-config=api/v1 \
|
--runtime-config=api/v1 \
|
||||||
--cert-dir="${TMPDIR:-/tmp/}" \
|
--cert-dir="${TMPDIR:-/tmp/}" \
|
||||||
|
--runtime_config="extensions/v1beta1=true" \
|
||||||
--service-cluster-ip-range="10.0.0.0/24" 1>&2 &
|
--service-cluster-ip-range="10.0.0.0/24" 1>&2 &
|
||||||
APISERVER_PID=$!
|
APISERVER_PID=$!
|
||||||
|
|
||||||
@ -217,26 +223,24 @@ runTests() {
|
|||||||
#######################
|
#######################
|
||||||
|
|
||||||
# Make sure the UI can be proxied
|
# Make sure the UI can be proxied
|
||||||
start-proxy --api-prefix=/
|
start-proxy
|
||||||
check-curl-proxy-code /ui 301
|
check-curl-proxy-code /ui 301
|
||||||
check-curl-proxy-code /metrics 200
|
check-curl-proxy-code /metrics 200
|
||||||
if [[ -n "${version}" ]]; then
|
|
||||||
check-curl-proxy-code /api/${version}/namespaces 200
|
|
||||||
fi
|
|
||||||
stop-proxy
|
|
||||||
|
|
||||||
# Default proxy locks you into the /api path (legacy behavior)
|
|
||||||
start-proxy
|
|
||||||
check-curl-proxy-code /ui 404
|
|
||||||
check-curl-proxy-code /metrics 404
|
|
||||||
check-curl-proxy-code /api/ui 404
|
check-curl-proxy-code /api/ui 404
|
||||||
if [[ -n "${version}" ]]; then
|
if [[ -n "${version}" ]]; then
|
||||||
check-curl-proxy-code /api/${version}/namespaces 200
|
check-curl-proxy-code /api/${version}/namespaces 200
|
||||||
fi
|
fi
|
||||||
|
check-curl-proxy-code /static/ 200
|
||||||
|
stop-proxy
|
||||||
|
|
||||||
|
# Make sure the in-development api is accessible by default
|
||||||
|
start-proxy
|
||||||
|
check-curl-proxy-code /apis 200
|
||||||
|
check-curl-proxy-code /apis/extensions/ 200
|
||||||
stop-proxy
|
stop-proxy
|
||||||
|
|
||||||
# Custom paths let you see everything.
|
# Custom paths let you see everything.
|
||||||
start-proxy --api-prefix=/custom
|
start-proxy /custom
|
||||||
check-curl-proxy-code /custom/ui 301
|
check-curl-proxy-code /custom/ui 301
|
||||||
check-curl-proxy-code /custom/metrics 200
|
check-curl-proxy-code /custom/metrics 200
|
||||||
if [[ -n "${version}" ]]; then
|
if [[ -n "${version}" ]]; then
|
||||||
|
@ -71,7 +71,7 @@ The above lets you 'curl localhost:8001/custom/api/v1/pods'
|
|||||||
}
|
}
|
||||||
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the specified prefix.")
|
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the specified prefix.")
|
||||||
cmd.Flags().StringP("www-prefix", "P", "/static/", "Prefix to serve static files under, if static file directory is specified.")
|
cmd.Flags().StringP("www-prefix", "P", "/static/", "Prefix to serve static files under, if static file directory is specified.")
|
||||||
cmd.Flags().StringP("api-prefix", "", "/api/", "Prefix to serve the proxied API under.")
|
cmd.Flags().StringP("api-prefix", "", "/", "Prefix to serve the proxied API under.")
|
||||||
cmd.Flags().String("accept-paths", kubectl.DefaultPathAcceptRE, "Regular expression for paths that the proxy should accept.")
|
cmd.Flags().String("accept-paths", kubectl.DefaultPathAcceptRE, "Regular expression for paths that the proxy should accept.")
|
||||||
cmd.Flags().String("reject-paths", kubectl.DefaultPathRejectRE, "Regular expression for paths that the proxy should reject.")
|
cmd.Flags().String("reject-paths", kubectl.DefaultPathRejectRE, "Regular expression for paths that the proxy should reject.")
|
||||||
cmd.Flags().String("accept-hosts", kubectl.DefaultHostAcceptRE, "Regular expression for hosts that the proxy should accept.")
|
cmd.Flags().String("accept-hosts", kubectl.DefaultHostAcceptRE, "Regular expression for hosts that the proxy should accept.")
|
||||||
|
Loading…
Reference in New Issue
Block a user