在Kubernetes Pod中访问Spring Boot Controller端点 [英] Accessing spring boot controller endpoint in kubernetes pod

查看:209
本文介绍了在Kubernetes Pod中访问Spring Boot Controller端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在kubernetes pod中部署了一个spring boot应用程序.但是通常我会以代理端口转发的方式访问任何应用-

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/

但是我的spring boot应用程序正在以下URL中运行-

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/

但是我不知道如何调用我的控制器端点/visitid

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

推荐答案

如果您只是想进行快速检查,则可以

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.

如果您尝试通过服务访问Pod,则可以

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.

这篇关于在Kubernetes Pod中访问Spring Boot Controller端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆