[英]Simple http request between two pods using Istio
我的前端 pod 正在嘗試與我的后端 pod 對話以獲取數據庫中的所有用戶。 當我在前端 pod 中的前端和 istio-proxy 容器中使用 curl 時,調用很簡單並且有效:
kubectl exec -it frontend-pod -c frontend-container -- bash
curl backend-svc:8000/users/
# returns correct response
kubectl exec -it frontend-pod -c istio-proxy -- bash
curl backend-svc:8000/users/
# returns correct response
但是,我的前端反應應用程序無法在 Chrome 中訪問此端點。 以下是控制台日志:
GET http://backend-svc:8000/users/ net::ERR_NAME_NOT_RESOLVED
看起來域名無法解析。 知道我在這里做錯了什么嗎?
我正在使用 nginx 為我的前端反應應用程序提供服務(不確定這是否可能是一個問題)。
編輯:一些反饋說我需要調整我的網關和/或虛擬服務文件。 這是它們現在的樣子:
# Source: myapp/gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: myapp-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- '*'
---
# Source: myapp/virtual-service.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myapp
spec:
hosts:
- '*'
gateways:
- myapp-gateway
http:
- route:
- destination:
host: frontend-svc
port:
number: 80
只是為了確保:您的呼叫是在客戶端觸發的嗎? 如果是,這就是原因,因為http://backend-svc:8000/users/
是由核心組件發布的 DNS 條目,並且僅在集群內部可用。
話雖如此,您應該創建一個網關自定義資源。 完整的描述在這里
網關允許將監控和路由規則等 Istio 功能應用於進入集群的流量。
希望我有所幫助。
您的代碼示例中有幾處看起來有問題:
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: bookinfo spec: hosts: - "*" gateways: - bookinfo-gateway http: - match: - uri: exact: /frontend route: - destination: host: frontend-svc port: number: 80
將這些東西拼湊在一起的一個很好的資源是Istio 入門頁面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.