java - 尝试通过 minikube/traefik 访问本地 http ://sge-api. 时网关错误

标签 java spring-boot docker kubernetes

我正在尝试使用 Kubernetes 和 Traefik 在本地部署 SpringBoot 应用程序,并使用本地 url。

我已经检查了 pod,日志也正常,看来应用程序正在等待我的调用。

但是当我使用Postman调用时:

GET http://sge-api.local/points/12345/search

我得到:

502 Bad Gateway

这是我的配置:

服务:

➜  sge git:(master) ✗ kubectl get service -n sge
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
sge-api-local   ClusterIP   10.109.84.138   <none>        8888/TCP   75m

入口:

➜  sge git:(master) ✗  kubectl get ingress -n sge
NAME             HOSTS           ADDRESS   PORTS   AGE
my-ingress   sge-api.local             80      75m

pods :

➜  sge git:(master) ✗ kubectl get logs -n sge sge-api-local-66d77d54ff-6fwc5

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2019-10-25 14:51:39.508  INFO 1 --- [           main] com.xxx.sge.MainApplication         : Starting MainApplication on sge-api-local-66d77d54ff-6fwc5 with PID 1 (/myapp.jar started by root in /)
2019-10-25 14:51:39.705  INFO 1 --- [           main] com.xxx.sge.MainApplication         : No active profile set, falling back to default profiles: default
2019-10-25 14:53:09.205  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$5ed484ef] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-10-25 14:53:10.704  INFO 1 --- [           main] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2019-10-25 14:53:39.002  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (https)
2019-10-25 14:53:41.107  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-10-25 14:53:41.203  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-10-25 14:53:50.004  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-10-25 14:53:50.004  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 125302 ms
2019-10-25 14:54:47.609  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-25 14:55:47.302  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (https) with context path ''
2019-10-25 14:55:47.902  INFO 1 --- [           main] com.xxx.sge.MainApplication         : Started MainApplication in 280.601 seconds (JVM running for 326.759)

我的应用程序在 traefik 仪表板中也显示正常。

我还有其他应用程序也在 .local url 中运行

我还在 /etc/hosts 中将 sge-api.local 设置为 127.0.0.1

这是我的入口:

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: sge-ingress
  namespace: sge
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: sge-api.local
    http:
      paths:
      - backend:
         serviceName: sge-api-local
         servicePort: 8888

我的服务:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: sge-api-local
  name: sge-api-local
  namespace: sge
spec:
  ports:
  - name: "8888"
    port: 8888
    targetPort: 8888
  selector:
    app: sge-api-local

我的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    reloader.stakater.com/auto: "true"
  labels:
    app: sge-api-local
  name: sge-api-local
  namespace: sge
spec:
  selector:
    matchLabels:
      app: sge-api-local
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: sge-api-local
    spec:
      containers:
      - image: sge_api:local
        name: sge-api-local

我应该做什么来调试这个?

最佳答案

您的 spring 应用程序正在监听端口 8081 上运行,这将不起作用。

2019-10-25 14:53:39.002  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (https)

调整您的服务以使用目标端口 8081 而不是 8888

关于java - 尝试通过 minikube/traefik 访问本地 http ://sge-api. 时网关错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58589127/

相关文章:

当容器仍在运行时,Docker 容器脚本返回退出代码 143

java - Spring @QuerydslPredicate 问题

java - 在反转二维数组时遇到问题?

java - 如何在 Spring Boot 中仅记录错误

java - CORS Spring Security Oauth2

java - 通过REST接口(interface)以可下载文件的形式返回进程的输出和错误流

docker - 将文件添加到 docker 容器以在启动期间使用

java - 我无法删除 mysql 表中的所有行

java - AlarmManager 不执行任何操作

.net - Docker中的.Net核心+ React + PostgreSQL