使用 Istio 实现应用迁移

背景:当前环境中有 Cluster A 和 Cluster B,各自部署了相同的应用,且该应用有两个域名用于处理不同的请求。目前,这两个域名的请求都由 Cluster A 中的应用处理。为进行应用迁移,现希望将域名 A 的请求继续由 Cluster A 处理,而域名 B 的请求则切换至由 Cluster B 中的应用来处理。

由于目前的流量处理都是由 Istio 负责,所以可以通过 ServiceEntry 来实现此需求。

创建一个 ServiceEntry:

将 b.nginx.com 的流量转发到 Cluster B 的 Istio Ingress Gateway,然后再通过 Cluster B 的 VirtualService 将流量转发到 Cluster B 中的应用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
name: external-nginx
namespace: default
spec:
addresses: {}
endpoints:
# 此处为 Cluster B 的 Istio Ingress Gateway 的地址和端口
- address: 172.16.0.104
ports:
http: 80
hosts:
- b.nginx.com
location: MESH_EXTERNAL
ports:
- name: http
number: 80
protocol: HTTP
resolution: DNS

修改原有的 VirtualService 中处理域名 B 流量的部份:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: nginx-virtualservice
namespace: default
spec:
gateways:
- http-gateway.istio-system.svc.cluster.local
hosts:
- a.nginx.com
- b.nginx.com
http:
- match:
- headers:
host:
exact: a.nginx.com
route:
- destination:
host: nginx.default.svc.cluster.local
port:
number: 80
- match:
- headers:
host:
exact: b.nginx.com
route:
- destination:
# 此处原本为 nginx.default.svc.cluster.local,如果要做迁移将其修改为 b.nginx.com 即可
host: b.nginx.com
port:
number: 80

尝试请求查看效果:

Author

Warner Chen

Posted on

2024-11-11

Updated on

2026-04-13

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.