js css html

demo 7 - 修改header

2023-01-14  本文已影响0人  程序员札记

Headers Operation

virtualservice-demoapp.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: demoapp
spec:
  hosts:
  - demoapp
  http:
  - name: canary
    match:
    - headers:
        x-canary: 
          exact: "true"
    route:
    - destination:
        host: demoapp
        subset: v11
      headers:
        request:
          set:
            User-Agent: Chrome
        response:
          add:
            x-canary: "true"
  - name: default
    headers:
      response:
        add:
          X-Envoy: test
    route:
    - destination:
        host: demoapp
        subset: v10

更新demoapp vs

# kubectl apply -f virtualservice-demoapp.yaml virtualservice.networking.istio.io/demoapp configured

访问demoapp

访问v10子集

root@client # curl   demoapp:8080
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-kdv4m, ServerIP: 172.20.154.195!
root@client # curl  demoapp:8080/user-agent
User-Agent: curl/7.67.0
root@client # curl -I  demoapp:8080
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
content-length: 116
server: envoy
date: Wed, 26 Oct 2022 08:51:25 GMT
x-envoy-upstream-service-time: 2
x-envoy: test

访问v11子集

root@client # curl  -H "x-canary: true" demoapp:8080
iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-hckjf, ServerIP: 172.20.89.189!
root@client # curl  -H "x-canary: true" demoapp:8080/user-agent
User-Agent: Chrome
root@client # curl -I -H "x-canary: true" demoapp:8080
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
content-length: 116
server: envoy
date: Wed, 26 Oct 2022 08:52:32 GMT
x-envoy-upstream-service-time: 114
x-canary: true

参考文档

Headers:https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#Headers

Headers.HeaderOperations:https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#Headers-HeaderOperations

上一篇 下一篇

猜你喜欢

热点阅读