
Proxy
The other command you can use to access your Pod is the kubectl proxy command. The proxy provides access not only to your Pod, but to all of the Kubernetes APIs as well. To invoke the proxy, run the following command:
kubectl proxy
And the output will show something akin to the following:
Starting to serve on 127.0.0.1:8001
Like the port-forward command, you won't get a prompt back in the Terminal window until the proxy terminates. While it is active, you can access Kubernetes REST API endpoints through this proxy. Open a browser and enter the URL http://localhost:8001/.
You should see a long list of URLs in JSON format, something akin to the following:
{
"paths": [
"/api",
"/api/v1",
"/apis",
"/apis/",
"/apis/admissionregistration.k8s.io",
"/apis/admissionregistration.k8s.io/v1alpha1",
"/apis/apiextensions.k8s.io",
"/apis/apiextensions.k8s.io/v1beta1",
"/apis/apiregistration.k8s.io",
These are accessing the Kubernetes infrastructure directly. One of those URL's is /api/v1 - and although it wasn't listed specifically, it uses the Kubernetes API server to provide a proxy to Pods based on the name. When we invoked our run command, we didn't specify a namespace, so it used the default, which is called default. The URL pattern to see a Pod is:
http://localhost:8001/api/v1/proxy/namespaces/<NAME_OF_NAMESPACE>/pods/<POD_NAME>/
And in the case of our Pod, this would be:
http://localhost:8001/api/v1/proxy/namespaces/default/pods/flask-1599974757-b68pw/
If you open a URL in your browser created with the Pod name that your Kubernetes cluster assigned, it should show you the same output that you saw using the port-forward command.