服務條目管理
更新時間 2024-09-09 19:32:03
最近更新時間: 2024-09-09 19:32:03
分享文章
本章節介紹服務條目管理
概述
在服務網格內部服務需要訪問的外部的場景下,可以使用服務條目(ServiceEntry)定義外部服務的訪問信息,這樣網格內的服務也可以訪問外部的服務。服務條目描述了服務的域名、協議、端口、節點列表等信息,定義服務條目時,需要注意端口不要與sidecar的端口沖突。
端口與服務條目
當前sidecar占用端口:
| 端口 | 協議 | 說明 |
|---|---|---|
| 15000 | TCP | sidecar管理端口。 |
| 15001 | TCP | outbound代理端口。 |
| 15004 | HTTP | debug端口。 |
| 15006 | TCP | inbound代理端口。 |
| 15008 | TCP | HBONE mTLS隧道端口。 |
| 15009 | H2C | HBONE安全網絡端口。 |
| 15020 | HTTP | 合并的指標采集端口。 |
| 15021 | HTTP | 健康檢查端口。 |
| 15053 | DNS | DNS端口。 |
| 15090 | HTTP | envoy指標采集端口。 |
| 18181 | HTTP | opa策略管理端口。 |
| 18282 | TCP | opa sidecar健康檢查端口。 |
| 19191 | GRPC | opa授權檢查端口。 |
通過集群與工作負載菜單下的服務條目可以管理網格內的外部服務;當前提供了三種模板用于創建服務條目,如下圖:

訪問網格外部的www.daliqc.cn服務可以按照下面的配置:
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
name: external-svc-https # Name for this ServiceEntry.
spec:
hosts: # External services that mesh can access.
- www.daliqc.cn
location: MESH_EXTERNAL #
Location can be MEST_EXTERNAL or MESH_INTERNAL.
ports: #
- number: 443
name: https
protocol: TLS # Access external
services over TLS.
resolution: DNS # Resolve
external services' IP address by DNS.
如果我們在虛機上部署了一組MongoDB的實例,但是并沒有注冊到網格上,可以按照如下的配置在網格內訪問MongoDB:
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
name:
external-svc-mongocluster # Name for this ServiceEntry.
spec:
hosts:
- mymongodb.somedomain # Not
used.
addresses:
- 192.192.192.192/24 # VIPs
ports:
- number: 27018
name: mongodb
protocol: MONGO
location: MESH_ EXTERNAL #
Location can be MEST_EXTERNAL or MESH_INTERNAL.
resolution: STATIC # Access
service by endpoints' static IP address.
endpoints:
- address: 2.2.2.2
- address: 3.3.3.3
注意服務條目里面的端口協議必須是HTTP|HTTPS|GRPC|HTTP2|MONGO|TCP|TLS里面的值。