Accessing spring boot controller endpoint in kubernetes pod

ぐ巨炮叔叔 提交于 2019-12-11 10:49:03

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/54204956/accessing-spring-boot-controller-endpoint-in-kubernetes-pod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!