Istio 是一个用于管理微服务通信的开源服务网格,其核心配置通过 Kubernetes 清单文件实现。以下是关键配置项与实践建议:

1. 核心配置项 🛠️

  • 服务发现
    使用 ServiceEntry 定义外部服务,例如:

    apiVersion: networking.istio.io/v1beta1
    kind: ServiceEntry
    metadata:
      name: external-db
    spec:
      hosts:
        - "database.example.com"
      ports:
        - number: 3306
          name: mysql
          protocol: tcp
      location: REGIONAL
    
    istio_service_entry
  • 流量路由
    通过 VirtualService 实现灰度发布或A/B测试,示例:

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: feature-toggle
    spec:
      hosts:
        - "api.example.com"
      http:
        routes:
        - destination:
            host: "api-bookinfo-v1"
          weight: 80
        - destination:
            host: "api-bookinfo-v2"
          weight: 20
    
    istio_virtualservice
  • 安全策略
    配置 mTLS 与 JWT 认证:

    apiVersion: security.istio.io/v1beta1
    kind: RequestAuthentication
    metadata:
      name: jwt-mtls
    spec:
      jwtRules:
      - from:
          - source: {}
        jwt:
          issuer: "auth.example.com"
          jwksUri: "https://auth.example.com/.well-known/jwks.json"
    
    istio_security_jwt

2. 配置工具推荐 🛠️

  • Kiali:可视化服务网格拓扑与流量
    点击查看 Kiali 配置教程
  • istioctl:命令行工具用于部署与调试
    istioctl install --set profile=demo -y
    
  • Envoy 配置:通过 DestinationRule 定义策略
    istio_envoy_config

3. 常见问题排查 🔍

  • 配置未生效?检查 meshConfig 中的 defaultConfig 设置
  • 服务无法访问?确认 ServiceEntrylocationports 配置
  • 需要监控配置?参考 Istio 监控指南

📌 提示:所有配置需在 Istio 控制平面部署后生效,建议通过 istioctl 验证配置状态。

istio_config_validation