---
title: Istio 入口网关与多域名路由(TLS、SNI 与 Gateway 实战)
date: 2025-11-26
keywords:
- Istio Gateway
- TLS
- SNI
- VirtualService
- 多域名路由
description: 配置Istio入口网关以支持多域名与TLS终止,通过SNI与VirtualService实现按域名与路径路由,并提供验证与可观测方法。
categories:
- 文章资讯
- 技术教程
---
概述
入口网关集中处理外部流量与TLS终止, 通过SNI与多主机匹配将请求路由到不同服务。统一证书与策略管理提升安全与可运维性。
关键实践与参数
- Gateway主机与端口: 按域名声明并启用TLS
- 凭据挂载:
credentialName引用K8s Secret证书 - 路由策略: 按
hosts与match路径分发 - 可观测: 在网关处采集访问日志与指标
示例/配置/实现
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: ingress-gw
spec:
selector:
istio: ingressgateway
servers:
- port: { number: 443, name: https, protocol: HTTPS }
hosts: ["example.com", "api.example.com"]
tls:
mode: SIMPLE
credentialName: ingress-cert
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: vs-web
spec:
hosts: ["example.com"]
gateways: ["ingress-gw"]
http:
- match: [{ uri: { prefix: "/" } }]
route:
- destination: { host: web.svc.cluster.local, port: { number: 80 } }
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: vs-api
spec:
hosts: ["api.example.com"]
gateways: ["ingress-gw"]
http:
- match: [{ uri: { prefix: "/v1" } }]
route:
- destination: { host: api.svc.cluster.local, port: { number: 80 } }
验证
- SNI与证书: 使用域名访问, 证书链与主机名匹配正确
- 路由正确性:
curl --resolve指定不同域名, 响应来自对应服务 - 观测数据: 在网关查看请求计数与状态码分布
- 策略变更: 修改路由与证书后行为符合预期
注意事项
- 证书定期轮换与权限控制
- 主机列表需精确匹配, 避免通配导致风险
- 与WAF与CDN策略协同, 保持头部与TLS一致
- 网关副本与资源需根据流量容量规划

发表评论 取消回复