mcpField
I
istio-traffic-management

istio-traffic-management

github.com/wshobsonクラウド・DevOps41.9k10.4k 回インストール2 週間前に更新
リポジトリ

istio-traffic-management について

本番の Istio サービスメッシュにおけるトラフィック設定ガイドです。ルーティングと耐障害性を管理するチーム向けに、リソースの説明、YAML テンプレート、ベストプラクティス、デバッグコマンドを紹介します。

主な機能

  1. 01VirtualService と DestinationRule の設定指針
  2. 02Ingress と外部サービスの設定
  3. 03カナリアおよびブルーグリーンデプロイのパターン
  4. 04リトライ、タイムアウト、サーキットブレーカー
  5. 05トラフィックミラーリングとフォールトインジェクションのテンプレート
  6. 06istioctl デバッグコマンド

活用シーン

  1. 01サービス間トラフィックのルーティング
  2. 02カナリアまたはブルーグリーンリリースのテスト
  3. 03リトライとサーキットブレーカーの設定
  4. 04テスト向けのトラフィックミラーリングや障害注入

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/wshobson/agents --skill istio-traffic-management

インストール後、Claude Code で/istio-traffic-managementを入力して読み込まれたか確認します。

詳細

Istio トラフィック管理

本番環境のサービスメッシュデプロイメント向けの Istio トラフィック管理に関する包括的なガイドです。

このスキルを使用する場面

  • サービス間ルーティングの設定
  • カナリアデプロイまたはブルーグリーンデプロイの実装
  • サーキットブレーカーと再試行の設定
  • ロードバランシングの設定
  • テスト用のトラフィックミラーリング
  • カオスエンジニアリングのためのフォールトインジェクション

中核となる概念

1. トラフィック管理リソース
リソース目的スコープ
VirtualServiceトラフィックを宛先へルーティングホストベース
DestinationRuleルーティング後のポリシーを定義サービスベース
Gatewayイングレス/エグレスを設定クラスターエッジ
ServiceEntry外部サービスを追加メッシュ全体
2. トラフィックフロー
Client → Gateway → VirtualService → DestinationRule → Service
                   (routing)        (policies)        (pods)

テンプレート

テンプレート 1: 基本的なルーティング
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: reviews-route
  namespace: bookinfo
spec:
  hosts:
    - reviews
  http:
    - match:
        - headers:
            end-user:
              exact: jason
      route:
        - destination:
            host: reviews
            subset: v2
    - route:
        - destination:
            host: reviews
            subset: v1
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: reviews-destination
  namespace: bookinfo
spec:
  host: reviews
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2
    - name: v3
      labels:
        version: v3
テンプレート 2: カナリアデプロイ
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: my-service-canary
spec:
  hosts:
    - my-service
  http:
    - route:
        - destination:
            host: my-service
            subset: stable
          weight: 90
        - destination:
            host: my-service
            subset: canary
          weight: 10
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: my-service-dr
spec:
  host: my-service
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 100
      http:
        h2UpgradePolicy: UPGRADE
        http1MaxPendingRequests: 100
        http2MaxRequests: 1000
  subsets:
    - name: stable
      labels:
        version: stable
    - name: canary
      labels:
        version: canary
テンプレート 3: サーキットブレーカー
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: circuit-breaker
spec:
  host: my-service
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 100
      http:
        http1MaxPendingRequests: 100
        http2MaxRequests: 1000
        maxRequestsPerConnection: 10
        maxRetries: 3
    outlierDetection:
      consecutive5xxErrors: 5
      interval: 30s
      baseEjectionTime: 30s
      maxEjectionPercent: 50
      minHealthPercent: 30
テンプレート 4: 再試行とタイムアウト
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-retry
spec:
  hosts:
    - ratings
  http:
    - route:
        - destination:
            host: ratings
      timeout: 10s
      retries:
        attempts: 3
        perTryTimeout: 3s
        retryOn: connect-failure,refused-stream,unavailable,cancelled,retriable-4xx,503
        retryRemoteLocalities: true
テンプレート 5: トラフィックミラーリング
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: mirror-traffic
spec:
  hosts:
    - my-service
  http:
    - route:
        - destination:
            host: my-service
            subset: v1
      mirror:
        host: my-service
        subset: v2
      mirrorPercentage:
        value: 100.0
テンプレート 6: フォールトインジェクション
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: fault-injection
spec:
  hosts:
    - ratings
  http:
    - fault:
        delay:
          percentage:
            value: 10
          fixedDelay: 5s
        abort:
          percentage:
            value: 5
          httpStatus: 503
      route:
        - destination:
            host: ratings
テンプレート 7: イングレスゲートウェイ
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: my-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 443
        name: https
        protocol: HTTPS
      tls:
        mode: SIMPLE
        credentialName: my-tls-secret
      hosts:
        - "*.example.com"
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: my-vs
spec:
  hosts:
    - "api.example.com"
  gateways:
    - my-gateway
  http:
    - match:
        - uri:
            prefix: /api/v1
      route:
        - destination:
            host: api-service
            port:
              number: 8080

ロードバランシング戦略

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: load-balancing
spec:
  host: my-service
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN # or LEAST_CONN, RANDOM, PASSTHROUGH
---
# Consistent hashing for sticky sessions
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: sticky-sessions
spec:
  host: my-service
  trafficPolicy:
    loadBalancer:
      consistentHash:
        httpHeaderName: x-user-id
        # or: httpCookie, useSourceIp, httpQueryParameterName

ベストプラクティス

推奨事項
  • シンプルに始める - 複雑さは段階的に追加する
  • サブセットを使用する - サービスのバージョンを明確にする
  • タイムアウトを設定する - 常に適切なタイムアウトを設定する
  • 再試行を有効にする - ただしバックオフと制限を付ける
  • 監視する - 可視性のために Kiali と Jaeger を使用する
非推奨事項
  • 過度な再試行をしない - カスケード障害を引き起こす可能性がある
  • 外れ値検出を無視しない - サーキットブレーカーを有効にする
  • 本番環境へミラーリングしない - テスト環境へミラーリングする
  • カナリアを省略しない - まず少ないトラフィック比率でテストする

デバッグコマンド

# Check VirtualService configuration
istioctl analyze

# View effective routes
istioctl proxy-config routes deploy/my-app -o json

# Check endpoint discovery
istioctl proxy-config endpoints deploy/my-app

# Debug traffic
istioctl proxy-config log deploy/my-app --level debug

コメント