首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试通过minikube / traefik访问http://sge-api.local时出现网关故障

尝试通过minikube / traefik访问http://sge-api.local时出现网关故障
EN

Stack Overflow用户
提问于 2019-10-28 18:18:53
回答 1查看 59关注 0票数 0

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

我已经检查过pod了,日志也没问题,看起来这个应用程序在等我的电话。

但是当我使用Postman打电话时:

代码语言:javascript
复制
GET http://sge-api.local/points/12345/search

我得到了:

代码语言:javascript
复制
502 Bad Gateway

下面是我的配置:

服务:

代码语言:javascript
复制
➜  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

入口:

代码语言:javascript
复制
➜  sge git:(master) ✗  kubectl get ingress -n sge
NAME             HOSTS           ADDRESS   PORTS   AGE
my-ingress   sge-api.local             80      75m

Pod:

代码语言:javascript
复制
➜  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网址运行

我还在sge-api.local为127.0.0.1的/etc/hosts中设置了一个条目

这是我的入口:

代码语言:javascript
复制
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

我的服务:

代码语言:javascript
复制
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

我的部署:

代码语言:javascript
复制
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

我应该怎么做才能调试这个?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-28 20:19:53

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

代码语言:javascript
复制
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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58589127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档