[英]Kubernetes – Curl works on service IP but not service name
我是 kubernetes 的新手,所以如果我跳過了一些明顯的步驟或不清楚我的問題,我深表歉意。
我已經定義了一個服務game-app-service
和一個部署game-app-deployment
。 這兩個都啟動並運行良好。
我正在嘗試將來自 API 網關服務(大使)的請求路由到此服務。 當嘗試從大使 pod 卷曲游戲應用服務端點時,我發現我總是收到空回復,並且它連接到一個不是服務 IP 的 IP。 但是,如果我game-app-service
的 IP 地址和它正在偵聽的端口換出game-app-service
:
curl -v -X POST 10.102.142.157:8084/api/test
一切正常,我從服務器得到了預期的響應。
我注意到curl -v -X POST game-app-service/api/test
解析為與curl -v -X POST random/api/test
– 92.242.140.21 port 80 相同的 IP。這讓我相信有些東西我的 DNS 解析有問題。 但是,我已驗證我的 core-dns pod 已啟動並正在運行,所以我不確定為什么會這樣。
下面,我列出了我的服務和部署的配置以供參考:
apiVersion: v1
kind: Service
metadata:
name: game-app-service
spec:
selector:
app: game-app-deployment
ports:
- protocol: TCP
port: 8084
targetPort: 8084
apiVersion: apps/v1
kind: Deployment
metadata:
name: game-app-deployment
labels:
app: game-app-deployment
spec:
replicas: 2
selector:
matchLabels:
app: game-app-deployment
template:
metadata:
labels:
app: game-app-deployment
spec:
containers:
- name: game-service-app
image: weflop/game-service-app
imagePullPolicy: Never
ports:
- containerPort: 8084
有沒有人知道為什么我不能使用我的服務名稱代替 IP 地址?
更新:
運行wget -O- game-service-app
給了我 200 的 HTTP 狀態,但響應為:
[<=>
] 0 --.-KB/s <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="refresh" content="0;url=https://searchassist.verizon.com/main?ParticipantID=euekiz39ksg8nwp7iqj2fp5wzfwi5q76&FailedURI=http%3A%2F%2Fgame-service-app%2F&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us"/><script type="text/javascript">url="https://searchassist.verizon.com/main?ParticipantID=euekiz39ksg8nwp7iqj2fp5wzfwi5q76&FailedURI=http%3A%2F%2Fgame-service-app%2F&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us";if(top.location!=location){var w=window,d=document,e=d.documentElement,b=d.body,x=w.innerWidth||e.clientWidth||b.clientWidth,y=w.innerHeight||e.clientHeight||b.clientHeight;url+="&w="+x+"&h="+y;}- [ <=>
表示 DNS 查找失敗。
事實證明,問題在於我的 API 網關與我的服務位於不同的命名空間中,這導致了問題。 通過指定“游戲服務應用程序”。 每當引用該服務時,我都能解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.