我们在GKE (Google Kubernetes Engine)上的Kubernetes集群中运行了几个服务,并且在使用Ingress配置路由时遇到了问题。
假设我们有auth-service和user-service,并希望通过以下urls访问它们:http://www.example.com/auth和http://www.example.com/user。应将对这些http://user-service/people的所有请求重定向到正确的服务并在内部路由(http://www.example.com/user/people -> urls )。
以下是我们对auth服务的配置:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: api-auth
spec:
replicas: 1
template:
metadata:
labels:
app: api-auth
tier: backend
track: stable
spec:
containers:
- name: api-auth
image: "<our-image>"
ports:
- name: http
containerPort: 9000
livenessProbe:
httpGet:
path: /health
port: 9000
initialDelaySeconds: 180
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: 9000
initialDelaySeconds: 180
timeoutSeconds: 5
---
kind: Service
apiVersion: v1
metadata:
name: auth-service
labels:
app: api-auth
spec:
type: NodePort
selector:
app: api-auth
tier: backend
ports:
- port: 80
targetPort: 9000在内部,该服务在Tomcat的9000端口上运行,这部分工作正常。
问题出在我们的Ingress配置上:
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: auth-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: <our-static-api>
kubernetes.io/ingress.class: "gce"
labels:
app: api-auth
spec:
rules:
- http:
paths:
- path: /auth
backend:
serviceName: auth-service
servicePort: 80
- path: /auth/*
backend:
serviceName: auth-service
servicePort: 80
- path: /user
backend:
serviceName: user-service
servicePort: 80
- path: /user/*
backend:
serviceName: user-service
servicePort: 80每当我以如下方式访问我们的静态应用程序接口(让我们暂时叫它example.com )时:http://www.example.com/auth,我得到了502 - Bad gateway。Running kubectl describe ingress说,我们的服务的运行状况是unknown。
我正在思考是什么导致了这种奇怪的行为。谁能给我指个方向?
发布于 2018-02-14 00:24:09
您在Slack上提到的这些服务是Spring Boot应用程序。这可能与此无关,但您需要确保入口路径与Spring Boot应用程序的上下文匹配,也就是说,如果您的入口路径是/user,则必须使用server.context-path=/user配置您的应用程序上下文。然后,可以在http://user-service/user下访问该服务。
发布于 2018-02-14 01:48:16
您的健康检查将reflect your readiness probes。健康检查需要使用您的nodePort端口,因为请求来自负载均衡器。如果您的运行状况检查针对端口9000,则请求将无法通过,因为节点上的该端口处于非活动状态。
确保您的LB运行状况检查的目标是正确的端口(在30000范围内),并且目标路径将响应为200,否则您的运行状况检查将继续失败,您将继续收到502个错误
https://stackoverflow.com/questions/48770749
复制相似问题