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

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

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

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

  • istio的环境准备

  • istioVirtualService

    • isti VirtualService 和 k8s Ingress
    • 使用 istio Gateway 允许外部访问
    • VirtualService 使用路径重写
    • 使用 DestinationRule Subset 进行路由分组(版本控制)
    • VirtualService 使用 header 重写路由
    • VirtualService 路由重定向
    • VirtualService 重试机制
    • VirtualService 混沌测试/错误注入
    • VirtualService 服务委托
    • VirtualService Header 操作
    • Gateway 支持 https 访问 - 标准模式
    • 使用 DestionationRule 流量控制策略 - 简单负载均衡
  • 老麦 Go
  • istioVirtualService
老麦
2023-02-01

VirtualService 服务委托

# 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
上次更新: 2023/04/05, 05:23:58
VirtualService 混沌测试/错误注入
VirtualService Header 操作

← VirtualService 混沌测试/错误注入 VirtualService Header 操作→

最近更新
01
How the creator of Angular is dehydrating the web (Ep 574)
06-07
02
For those who just don’t Git it (Ep 573)
06-07
03
Modern work requires attention. Constant alerts steal it
06-07
更多文章>
Theme by Vdoing | Copyright © 2022-2024 IT七剑客 | MIT License
  • 闽ICP备2021006579号-4
  • 闽公网安备 35012102500470号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式