[英]Getting 502 Bad Gateway while calling an end point configured in spring boot application deployed in GCP
[英]Getting 502 Bad Gateway (Nginx) while accessing Java application deployed on kubernetes pod
我在访问 java 应用程序时收到 502 Badgateway(nginx)。我已经在 kubernetes 集群上以 pod 的形式部署了应用程序
部署.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 文件
---
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 文件
---
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"]
从入口路径 url 访问我的应用程序时,我得到 502 Badgateway(nginx),我尝试做 curl 但从那里我也得到了坏网关,并知道如何解决这个问题。
在我的 application.properties 文件(代码文件)中,端口是 8080(server.port 值),但在我的目标端口中,service.yaml 文件中的端口是 8010,所以我在我的 service.yaml 文件中将目标端口更改为 8080文件和问题已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.