Bad Gateway when trying to access to http://sge-api.local via minikube / traefik

10/28/2019

I'm trying to deploy a SpringBoot app in local with Kubernetes and Traefik, with local url.

I already checked the pod, and the logs are OK, it seems the app is waiting for my calls.

But when I use Postman to call:

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

I get:

502 Bad Gateway

Here is my config:

Service:

➜  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

Ingress:

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

Pod:

➜  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)

My app also appears OK in traefik dashboard.

I have others app that also run in .local url

I also have set an entry in /etc/hosts with sge-api.local to 127.0.0.1

Here is my ingress:

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

My service :

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

My deployment:

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

What should I do to debug this ?

-- Juliatzin
docker
java
kubernetes
spring-boot

1 Answer

10/28/2019

You have the spring application running with listening port 8081, this will not work.

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

Adjust your service to use target port 8081 instead of 8888

-- Thomas
Source: StackOverflow