[英]Istio Gateway and VirtualService issue with Kubernetes Dashboard
[英]istio virtualservice vs gateway
我正在嘗試圍繞 istio 中的虛擬服務工作。 我在 minikube 上運行 istio 並有以下 yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: istio-test-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-test
spec:
hosts:
- istio-service-test.default.svc.cluster.local
# - "*"
gateways:
- istio-test-gateway
http:
- name: "pingpongservice"
route:
- destination:
host: istio-service-test.default.svc.cluster.local
在VirtualService
hosts
部分下,我定義了一個實際的主機,我試圖弄清楚它是如何工作的。 在 minikube 上,我運行以下命令來獲取 url
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
export INGRESS_HOST=$(minikube ip)
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
一旦我部署它並嘗試使用curl "http://${GATEWAY_URL}/ping
之類的 curl 我什么也得不到。如果我取消注釋*
並注釋掉istio-service-test.default.svc.cluster.local
在VirtualService
hosts
部分istio-service-test.default.svc.cluster.local
然后它工作,我成功地從服務器獲得響應。我不確定這里發生了什么。理想情況下,我想要做的是使用類似http://istio-service-test/ping
東西訪問服務http://istio-service-test/ping
VirtualService hosts:
行需要匹配 HTTP Host:
標頭。 HTTP 客戶端通常會從此處的 URL 傳遞主機名,但有時您可以覆蓋它
curl -H 'Host: istio-service-test.default.svc.cluster.local' \
"http://${GATEWAY_URL}/ping"
如果您將 VirtualService 綁定到入口網關,則hosts:
需要匹配路由到集群的外部DNS 名稱,或者是*
。 如果您的集群為基於主機的路由運行多個應用程序,您可以使用它。
如果 VirtualService 沒有專門綁定到 Gateway (或明確綁定到mesh
),則hosts:
需要匹配服務的 Kubernetes 內部 DNS 名稱,並且它圍繞該集群內服務提供入口類型的路由功能。 這將允許您為其他 ClusterIP 類型的服務執行基於路徑或基於標頭的路由,而無需運行您自己的中間反向代理。
對於您的使用,您將 VirtualService 綁定到入口網關,您只在集群中運行一個應用程序,並且 minikube 安裝沒有持久的 DNS 名稱, hosts: [*]
可能是正確的設置.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.