【问题标题】:Accessing spring boot controller endpoint in kubernetes pod访问 kubernetes pod 中的 spring boot 控制器端点
【发布时间】:2019-06-09 19:48:03
【问题描述】:

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

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

但我的 Spring Boot 应用程序正在下面的 url 中运行 -

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

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

【问题讨论】:

  • k8s 中的 Pod 旨在通过服务访问,因此请尝试部署一个并将流量转发到您的 Pod。通常的顺序是入口 -> 服务 -> pod

标签: spring-boot docker kubernetes kubectl kubernetes-ingress


【解决方案1】:

如果您只是想进行快速检查,那么您可以 port-forward to the pod - 执行 kubectl get pods 以查找 pod 名称,然后找到 kubectl port-forward <pod-name> 8080:8080 或您使用的任何端口(如果不是 8080)。然后您可以点击您的端点您的浏览器或本地主机上的 curl。例如,如果您正在运行 spring boot 执行器,您可以转到 http://localhost:8080/actuator/health。

如果您尝试通过 Service 访问 Pod,则可以port-forward to the Service,但您可能希望将 Service 公开到外部。您需要选择how to expose it externally 并进行设置。然后,您将拥有一个可以使用的外部 URL,而无需通过 kube 内部 API。

也可以to construct a URL to hit the Service when proxying with kubectl proxy。例如,您可以使用带有api/v1/namespaces/<namespace>/services/<http:><service_name>:<port_name>/proxy/actuator/health 的http(不是https)在spring boot 应用程序上点击执行器。 <port_name> 将在服务规范中,您将在 kubectl describe service 的输出中找到它。

【讨论】:

猜你喜欢
  • 2018-04-17
  • 2019-05-02
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2019-01-28
  • 2021-03-23
  • 2019-09-21
  • 2019-01-03
相关资源
最近更新 更多