How can I access an internal HTTP port of a Kubernetes node in Google Cloud Platform

3/3/2018

I have a load-balanced service running in a Kubernetes cluster on the Google Cloud Platform. The individual servers expose some debugging information via a particular URL path. I would like to be able to access those individual server URLs, otherwise I just get whichever server the load balancer sends the request to.

What is the easiest way to get access to those internal nodes? Ideally, I'd like to be able to access them via a browser, but if I can only access via a command line (e.g. via ssh or Google Cloud Shell) I'm willing to run curl to get the debugging info.

-- Mark Friedman
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

4/5/2018

Port Forward can be used as described in answer from Radek, and it has many advantages. The disadvantage is that it is quite slow, and if you are having a script doing many calles, there is another option for you.

kubectl run curl-mark-friedman --image=radial/busyboxplus:curl -i --tty --rm

This will create a new POD on you network with a busybox that includes the curl command. You can now use interactive mode in that POD to execute curl commands to other PODS from within the network.

You can find many images with the tools included that you like on docker hub. If you for example need jq, there is an image for that:

kubectl run curl-jq-mark-friedman --image=devorbitus/ubuntu-bash-jq-curl -i --tty --rm

The --rm option is used to remove the POD when you are done with it. If you want the POD to stay alive, just remove that option. You may then attach to that POD again using:

kubectl get pods | grep curl-mark-friedman <- get your <POD ID> from here.

kubectl attach <POD ID> -c curl-mark-friedman -i -t

-- Andreas Lundgren
Source: StackOverflow

3/3/2018

I think the simplest tool for you would be kubectl proxy or maybe even simpler kubectl port-forward. With the first you can use one endpoint and the apiserver ability to proxy to particular pod by providing appropriate URL.

kubectl proxy

After running kubectl proxy you should be able to open http://127.0.0.1:8001/ in your local browser and see a bunch of paths available on the API server. From there you can proceed with URL like ie. http://127.0.0.1:8001/api/v1/namespaces/default/pods/my-pod-name:80/proxy/ which will proxy to port 80 of your particular pod.

kubectl port-forward

Will do similar but directly to port on your pod : kubectl port-forward my-pod-name 8081:80. At that point any request to 127.0.0.1:8081 will be forwarded to your pods port 80

-- Radek 'Goblin' Pieczonka
Source: StackOverflow