Accessing spring boot controller endpoint in kubernetes pod

1/15/2019

I deployed a spring boot app in kubernetes pod. But normally I access any app in this way of proxy port forwarding -

http://192.64.125.29:8001/api/v1/namespaces/kube-system/services/https:hello-app:/proxy/

But my spring boot app is running in this below url -

http://192.64.125.29:8001/api/v1/namespaces/kube-system/services/https:myspringbootapp:/proxy/

But I have no idea how to invoke my controller end point /visitid

-- Gopi
docker
kubectl
kubernetes
kubernetes-ingress
spring-boot

1 Answer

1/15/2019

If you are just trying to do a quick check then you can port-forward to the pod - do kubectl get pods to find the pod name and then kubectl port-forward <pod-name> 8080:8080 or whatever port you use if not 8080. Then you can hit your endpoint in your browser or with curl on localhost. For example, if you have the spring boot actuator running you could go to http://localhost:8080/actuator/health.

If you are trying to access the Pod through the Service then you can port-forward to the Service but you may want to expose the Service externally. You'll want to pick how to expose it externally and set that up. Then you'll have an external URL you can use and won't need to go via the kube internal APIs.

It is also possible to construct a URL to hit the Service when proxying with kubectl proxy. For example you could hit the actuator on a spring boot app using http (not https) with api/v1/namespaces/<namespace>/services/<http:><service_name>:<port_name>/proxy/actuator/health. The <port_name> will be in the service spec and you'll find it in the output of kubectl describe service.

-- Ryan Dawson
Source: StackOverflow