Getting 502 Bad Gateway (Nginx) while accessing Java application deployed on kubernetes pod

594 Views Asked by At

I am getting 502 Badgateway(nginx) while accessing the java application.I have deployed application in the form of pod on kubernetes cluster

deployment.yaml file

--
  apiVersion: "apps/v1"
  kind: "Deployment"
  metadata: 
    name: "app-development"
    namespace: "development"
  spec: 
    selector: 
      matchLabels: 
        app: "app-development"
    replicas: 1
    strategy: 
      type: "RollingUpdate"
      rollingUpdate: 
        maxSurge: 1
        maxUnavailable: 1
    minReadySeconds: 5
    template: 
      metadata: 
        labels: 
          app: "app-development"
      spec: 
        containers: 
          - 
            name: "app-development"
            image: "appimage:latest"
            imagePullPolicy: "Always"
            env: 
              - 
                name: "NODE_ENV"
                value: "development"
            ports: 
              - 
                containerPort: 40912
        imagePullSecrets: 
          - 
            name: "app-service"

ingress.yaml file

---
  apiVersion: "networking.k8s.io/v1beta1"
  kind: "Ingress"
  metadata: 
    name: "app-ingress"
    namespace: "app-development"
    annotations: 
      nginx.ingress.kubernetes.io/rewrite-target: "/"
  spec: 
    rules: 
      - 
        host: "localhost"
        http: 
          paths: 
            - 
              backend: 
                serviceName: "app-development"
                servicePort: 40912
              path: "/app-development"

service.yaml file

---
  apiVersion: "v1"
  kind: "Service"
  metadata: 
    name: "app-development"
    namespace: "app-development"
    labels: 
      app: "app-development"
  spec: 
    ports: 
      - 
        port: 40912
        targetPort: 8010
    selector: 
      app: "app-development"

dockerfile

FROM openjdk:8-jdk-alpine
EXPOSE 8010
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD . /usr/src/app
ADD target/app.jar /usr/src/app
ENTRYPOINT ["java","-jar","/usr/src/app/app.jar"]

While accessing my application from ingress path url I am getting 502 Badgateway(nginx), I tried doing curl but from there also I am getting bad gateway, and idea how to resolve the issue.

1

There are 1 best solutions below

0
On

In my application.properties file(code file) the port was 8080 (server.port value), but in my target port the port was 8010 in service.yaml file, so I have change the target port to 8080 in my service.yaml file and issue resolved.