I have recently been working on building some tools using the kubernetes API. To enable this develoment locally I am running kubernetes using minikube. If you haven’t check this out yet and want to learn kubernetes, this is an awesome local environment to get started with.

The issue is, when running minikube, how do you access the kubernetes API since the API server is not accessible to any environment outside the kubernetes cluster? For Example, if the k8s api server IP address is 10.96.0.1 and you would like to access the swagger endpoint. You would try http(s)://10.96.0.1/swaggerapi but you come across this… endpoint error

Maybe it’s the minikube host IP that we should access. Assuming our host IP address is 192.168.64.8, let’s try to access the swagger api endpoint using the host IP. host error

Ok, both methods we have tried are unsucessful, so what’s next? It turns out that kubernetes has a proxy option on the kubectl CLI (command line interface) that will help you expost the API endpoint to the local host. If you execute the proxy command you will create a proxy for the kubernetes services that you will be able to access from your localhost.

execute the following

kubectl proxy

and you should see proxy starting…

Now that we have the proxy started (note that it is listening on port 8001) we should be able to access the api endpoints from our localhost. For example, if our localhost IP address is 192.168.64.8 and the proxy server is running, you should be able to access the swagger api endpoint like this, http(s)://192.168.64.8:8001/swaggerapi

and indeed we can! swagger success

Now that we can access the kubernetes API server from localhost, we can start developing with the API without having to spin up a shiney new linux environment. ;)

As always feel free to reach out to me on twitter for any questions or suggestions.