【Path Redirect】請(qǐng)求路徑重定向
更新時(shí)間:
配置請(qǐng)求路徑重定向可以使得發(fā)往服務(wù)的指定請(qǐng)求獲得HTTP 301重定向響應(yīng),將請(qǐng)求重定向到服務(wù)的其它路徑上。本文介紹如何配置請(qǐng)求路徑重定向。
前提條件
已完成準(zhǔn)備工作,并部署httpbin服務(wù)和sleep服務(wù)。具體操作,請(qǐng)參見(jiàn)準(zhǔn)備工作。
操作步驟
使用istioctl工具,執(zhí)行以下命令,為httpbin服務(wù)部署Waypoint代理。
istioctl x waypoint apply --service-account httpbin
預(yù)期輸出:
waypoint default/httpbin applied
為httpbin服務(wù)配置虛擬服務(wù),將發(fā)往httpbin服務(wù)根路徑的請(qǐng)求轉(zhuǎn)發(fā)至
/get
路徑。登錄ASM控制臺(tái),在左側(cè)導(dǎo)航欄,選擇 。
在網(wǎng)格管理頁(yè)面,單擊目標(biāo)實(shí)例名稱(chēng),然后在左側(cè)導(dǎo)航欄,選擇 ,然后單擊創(chuàng)建。
在創(chuàng)建頁(yè)面,進(jìn)行如下配置,單擊預(yù)覽,確認(rèn)YAML內(nèi)容無(wú)誤后,單擊確認(rèn),然后單擊創(chuàng)建。
apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: httpbin namespace: default spec: hosts: - httpbin.default.svc.cluster.local http: - match: - uri: exact: / redirect: uri: /get
執(zhí)行以下命令,驗(yàn)證請(qǐng)求路徑重定向是否生效。
kubectl exec -it deploy/sleep -- curl httpbin:8000 -I
預(yù)期輸出:
HTTP/1.1 301 Moved Permanently location: http://httpbin:8000/get date: xxx, xx Aug 2023 11:xx:xx GMT server: istio-envoy transfer-encoding: chunked
可以看到在sleep容器內(nèi)部訪(fǎng)問(wèn)httpbin服務(wù)的根路徑,返回301響應(yīng),其中
location
字段為http://httpbin:8000/get
,表示請(qǐng)求被重定向到httpbin服務(wù)的/get
路徑。
文檔內(nèi)容是否對(duì)您有幫助?