You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot服务Actuator API在Kubernetes Pod中部署后无法访问

解决方案:SpringBoot微服务部署到Kubernetes后无法访问接口

1. 确认Pod状态与服务启动日志

先排查Pod运行状态和服务启动是否正常:

  • 查看Pod状态:
    kubectl get pods
    
    确保Pod状态为Running,重启次数为0。
  • 检查服务启动日志,重点确认Tomcat绑定地址:
    kubectl logs <你的Pod名称>
    
    日志中需出现类似Tomcat started on port(s): 8080 (http) with context path ''的内容,且明确标注绑定地址为0.0.0.0(若绑定127.0.0.1,外部将无法访问服务)。

2. 验证Pod内部接口可达性

进入Pod内部直接测试接口,确认服务本身功能正常:

kubectl exec -it <你的Pod名称> -- /bin/bash
# 在Pod内部执行curl请求
curl http://localhost:8080/actuator/health

若返回正常响应,说明服务本身无问题,问题出在网络路由层面;若无法访问,检查环境变量是否生效(如server.port、management.endpoints.web.exposure.include是否正确加载)。

3. 检查Service与Pod的关联有效性

确认Service正确关联到目标Pod:

  • 查看Service的Endpoints信息:
    kubectl get endpoints com-etl-my-service
    
    输出中需包含Pod的IP地址和8080端口,若为空,说明Deployment的metadata.labels与Service的spec.selector标签不匹配,需修正标签一致性。
  • 查看Service详情:
    kubectl describe service com-etl-my-service
    
    确认Selector字段为app: com-etl-my,与Pod的标签完全一致。

4. 正确访问NodePort服务

你的Service类型为NodePort,外部访问需使用NodeIP + NodePort,而非直接使用8080端口:

  • 查看分配的NodePort端口:
    kubectl get service com-etl-my-service
    
    输出的NODE_PORT列会显示一个30000-32767之间的端口(例如31567)。
  • 访问地址:
    由于是Docker Desktop的Kubernetes集群,NodeIP即为localhost,最终访问地址为:
    http://localhost:<NODE_PORT>/actuator/health
    

5. 临时调试:使用port-forward直接访问Pod

若NodePort访问仍有问题,可通过port-forward绕过Service直接访问Pod,快速定位问题:

kubectl port-forward pod/<你的Pod名称> 8080:8080

此时在本地访问http://localhost:8080/actuator/health,若能正常响应,说明Service配置或集群网络策略存在问题;若仍无法访问,回到Pod内部进一步排查服务启动状态。

内容的提问来源于stack exchange,提问作者Bhushan Gadekar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 09:32:51