David - Musings of an SRE

Using Kubectl proxy to access your Kubernetes services

Sometimes it might be quite difficult to access your kubernetes services if your infrastructure isn’t able to properly support both LoadBalancer and NodePort service types.

Or maybe you just want to quickly access your services securely without having it be exposed to the public internet.

kubectl proxy is a great tool for you to do just that.

First, run kubectl proxy on your local machine. This exposes and proxies port 8081 to your Kubernetes Master. This allows you make calls to your Kubernetes API securely without having to send your tokens directly.

With your proxy running, all you really need to do to access your web-services is just redirecting your browser to

http://localhost:8001/api/v1/proxy/namespaces/<namespace>/services/<service_name>:<service_port>

For example, if you have a service called prometheus that lives in the namespace default and is listening to port 9090.

Hitting http://localhost:8001/api/v1/proxy/namespaces/default/services/prometheus:9090 will make a http call to your service.

References