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

启用Actuator的Spring Boot应用在K8中访问/actuator报404

Kubernetes中Spring Boot应用Actuator端点404问题排查

我有一个部署在Kubernetes(简称K8s)中的Spring Boot Web应用,本地使用完全相同配置运行正常,但在K8s中进入Pod执行curl localhost:8080/actuator时返回Apache Tomcat/9.0.73的404错误页面。

配置概要

  • spring-boot-starter版本:2.7.10
  • Tomcat仅提供Actuator端点
  • K8s中Java版本为1.8.0_345,本地为1.8.0_151

应用配置(application.yaml)

server:
  port: 8080
  error:
    whitelabel:
      enabled: true
    include-exception: true
    include-message: always
    include-binding-errors: always
    include-stacktrace: always
  servlet:
    context-path: '/' 


logging:
  level:
    org:
      apache:
        tomcat: DEBUG
        catalina: DEBUG
      springframework:
        web:
          filter:
            CommonsRequestLoggingFilter: DEBUG

# actuator
management:
  endpoints:
    enabled-by-default: true
    web.exposure.include: "*"
  endpoint:
    shutdown.enabled: false
    info.enabled: true



hikariCP:
  dataSourceClassName: com.microsoft.sqlserver.jdbc.SQLServerDataSource

spring:
  # Preferred JSON mapper to use for HTTP message conversion.
  mvc.converters.preferred-json-mapper: gson
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
  datasource:
    bet:
      url: someserver
      username: MSSQL_USER
      password: MSSQL_PASS
      hikari:
        poolName: betHikariCP
        maximum-pool-size: 5
        connectionTimeout: 30000
        idleTimeout: 600000
        maxLifetime: 1800000

观测到的行为

  • 本地可正常访问localhost:8080/actuator,访问错误路径时返回JSON格式404;但K8s中返回Tomcat的HTML 404页面
  • 本地和K8s的日志均显示Tomcat正常启动、Actuator端点已暴露,但K8s中配置的CommonsRequestLoggingFilter无请求日志输出

CommonsRequestLoggingFilter配置

@Bean
    public CommonsRequestLoggingFilter logFilter() {
        CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter();
        filter.setIncludeQueryString(true);
        filter.setIncludeHeaders(false);
        filter.setBeforeMessagePrefix("PRE-REQUEST: ");
        filter.setAfterMessagePrefix("POST-REQUEST: ");
        return filter;
    }

目前排查情况

  • 开启Tomcat/Catalina调试日志等,仍无法找到路由未解析的原因
  • 日志中无异常信息
  • 已排除K8s的Nginx/Ingress配置问题

Pod清单及启动脚本

原文中Pod清单、app-configure-n-start.sh、start脚本内容保持不变

请求帮助

请提供额外的排查日志配置建议,或可能的问题原因。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 19:55:40