简体   繁体   English

在访问部署在 kubernetes pod 上的 Java 应用程序时获取 502 Bad Gateway (Nginx)

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

I am getting 502 Badgateway(nginx) while accessing the java application.I have deployed application in the form of pod on kubernetes cluster我在访问 java 应用程序时收到 502 Badgateway(nginx)。我已经在 kubernetes 集群上以 pod 的形式部署了应用程序

deployment.yaml file部署.yaml 文件

--
  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 ingress.yaml 文件

---
  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 service.yaml 文件

---
  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 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.从入口路径 url 访问我的应用程序时,我得到 502 Badgateway(nginx),我尝试做 curl 但从那里我也得到了坏网关,并知道如何解决这个问题。

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.在我的 application.properties 文件(代码文件)中,端口是 8080(server.port 值),但在我的目标端口中,service.yaml 文件中的端口是 8010,所以我在我的 service.yaml 文件中将目标端口更改为 8080文件和问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用在GCP中部署的Spring Boot应用程序中配置的端点时获取502 Bad Gateway - Getting 502 Bad Gateway while calling an end point configured in spring boot application deployed in GCP Java AWS 服务器:502 错误网关 nginx/1.8.1 - Java AWS Server: 502 Bad Gateway nginx/1.8.1 Beanstalk 502 Bad Gateway Spring应用程序 - Beanstalk 502 Bad Gateway Spring application Azure Java功能-502-Bad Gateway - Azure Java function -502-Bad Gateway GAE Java Flexible env 502坏网关 - GAE Java Flexible env 502 bad gateway 验证密码时出现“ 502错误的网关:请求端点无法处理” - Getting “502 bad gateway: request endpoint unable to handle” while validating the password Haproxy Bad Gateway 502 - Haproxy Bad Gateway 502 将Spring Boot应用程序部署到Elastic Beanstalk时出现502 Bad Gateway - 502 Bad Gateway when deploying Spring Boot application to Elastic Beanstalk 我在使用 Microsoft Graph Api 甚至使用 PowerShell 命令创建团队时收到 502 Bad gateway 错误 - I am getting 502 Bad gateway error while creating team using Microsoft Graph Api and even using PowerShell commands 从 java 应用程序到 kubernetes pod 执行命令 - Execute command from java application to kubernetes pod
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM