我试图使用Spring Gateway将请求路由到一些暴露REST API的Spring Boot pods。
我有一个搜索服务的部署是这样的,它部署得很好,如果我使用ngnix ingress部署就可以访问。
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: search
name: search
spec:
replicas: 1
selector:
matchLabels:
app: search
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
app: search
spec:
containers:
- image: <ommited>
name: search-service
imagePullPolicy: Always
resources: {}
imagePullSecrets:
- name: <ommited>
status: {}
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: search
name: search
spec:
ports:
- name: stage
port: 8080
protocol: TCP
selector:
app: search
type: ClusterIP
我想使用Spring Gateway作为入口点,所以我把它部署在另一个pod中,就像这样。
<ommiting deployment>
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: gateway
name: gateway
spec:
ports:
- name: stage
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: gateway
type: LoadBalancer
有一个定义的路由。
.route("search", r -> r.path("/search")
.uri("http://search:8080/search"))
它也能很好地部署,并且可以从外部访问。
然而,当网关pod试图将请求路由到搜索pod时,它得到一个明确的 "连接拒绝"。
{
"timestamp": "...",
"path": "/search",
"status": 500,
"error": "Internal Server Error",
"message": "finishConnect(..) failed: Connection refused: search/10.100.130.149:8080",
"requestId": "a3af8165-1"
}
主机名被正确解析。
也尝试过从网关连接到搜索 nc
:
kubectl exec -it gateway-7798cb658-ffzvb -- nc -z search 8080
command terminated with exit code 1
再次主机是正确解决,所以期望我有错误配置端口的地方.我已经验证了搜索Spring Boot应用程序在8080上监听,8080通过docker容器和搜索pod暴露。
任何帮助感激,谢谢!
检查以下的描述 search
服务,使用命令 kubectl describe svc search
并验证 port
是与端口匹配的 (containerPort
)的播客正在收听。你也可以定义一个 targetPort
的服务中,明确指向 port(containerPort
容器正在监听)。