[英]Kubernetes pod gives “connection refused” when trying to connect via ClusterIp
我正在嘗試使用 Spring 網關將請求路由到一些 Spring 引導 pod 暴露 REST API。
我有一個像這樣部署的搜索服務:
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
如果我使用 ngnix 入口部署,它可以很好地部署並且可以訪問。 我想使用 Spring 網關作為入口點,但是我將它部署在另一個 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 公開的。
任何幫助表示贊賞,謝謝!
使用命令kubectl describe svc search
檢查search
服務的描述,並驗證port
是否與 pod 正在偵聽的端口 ( containerPort
) 匹配。 您還可以在服務中定義一個targetPort
以明確指向容器正在偵聽的端口( containerPort
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.