IT七剑客 IT七剑客
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
  • 从零开始写 k8s 发布工具(一)

  • 从零开始写 k8s 发布工具(二)

  • 从零开始写 k8s 发布工具(三)

  • 从零开始写 k8s 发布工具(四)

  • istio的环境准备

  • istioVirtualService

    • vs-and-ingress
    • gateway
    • vs-http-rewrite-by-uri
    • dr-subset
    • vs-http-rewrite-by-header
    • vs-http-redirect
    • vs-http-retry
    • vs-http-fault-injection
    • vs-http-delegate
    • vs-http-header-operation
    • gw-https-support-standard
    • dr-simple-loadbalance
  • 老麦 Go
  • istioVirtualService
老麦
2023-02-01

vs-http-delegate

# VirtualService 服务委托

服务委托就是流量转发。

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

delegate.png

如下 VirtualService 的 流量委托 定义, 是在 myistio 这个命名空间中创建的。 但是将 myistio.tangx.in/prod 的流量转发到了命名空间 myistio-prod 中的 prod 服务中; 同样将 myistio.tangx.in/reviews 的流量转发到了命名空间 myistio-review 中的 review 服务中。

# vs http delegate
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-delegate
  namespace: myistio # 注意 namespace
spec:
  gateways:
    - istio-tangx-in
  hosts:
    - istio.tangx.in
  http:
    - match:
        - uri:
            prefix: "/prod"
      delegate:
        name: vs-prod   # vs name
        namespace: myistio-prod
    - match:
        - uri:
            prefix: "/review"
      delegate:
        name: vs-review  # vs name
        namespace: myistio-review
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

需要注意 被委托对象 必须是 VirtualService 对象, 例如 myistio-prod 命名空间中的 vs-prod 对象

# vs prod
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-prod
  namespace: myistio-prod # 注意 namespace
spec:
  # hosts:                  # 这里不能设置 hosts, 即使是对外暴露的相同域名也不行,
                            # 否则可能出现 404 
  #   - myistio.tangx.in
  http:
    - route:
        - destination:
            host: svc-prod
1
2
3
4
5
6
7
8
9
10
11
12
13
14

同样需要 注意 在定义 被委托对象(vs-prod) 时, 不能指定 .spec.hosts 的值, 否则流量转发异常, 可能出现 404。

delegate-404.png

如果熟悉 nginx 的话, 可能会很好理解

# nginx.conf
server {

    listen 80;
    server_name tangx.in;

    location ~ /prod {
        proxy_pass http://vs-prod.myistio-prod:80/
    }

    location ~ /review {
        proxy_pass http://vs-review.myistio-review:80/
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
编辑 (opens new window)
上次更新: 2023/02/05, 02:48:13
vs-http-fault-injection
vs-http-header-operation

← vs-http-fault-injection vs-http-header-operation→

最近更新
01
Coding 102 Writing code other people can read
02-26
02
Kotlin Flow响应式编程,StateFlow和SharedFlow
02-05
03
Kotlin Flow响应式编程,操作符函数进阶
02-05
更多文章>
Theme by Vdoing | Copyright © 2022-2023 IT七剑客 | MIT License
  • 闽ICP备2021006579号-4
  • 闽公网安备 35012102500470号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式