Istioを既存プロジェクトに統合する方法
既にIstio公式のBookinfoアプリケーションのデプロイとトラフィック管理について学びました。では、自社プロジェクトのCI/CDパイプラインでIstioをどのように活用すればよいでしょうか。
- デプロイ先のnamespaceでIstioの自動サイドカーインジェクションを有効化する
- Bookinfoアプリケーションを参考に、プロジェクトに対応するGateway、VirtualService、DestinationRuleなどのカスタムリソースを定義する
- Kustomizeマニフェストを使用してリソースを管理する
- CI/CDプロセスはArgoCDなどのGitOpsツールで実装する
Istio適応プロジェクトの特性
Istio導入を検討する際のポイント:
- サービスメッシュ基盤の分離によるアプリケーション構造の簡素化
- 既存のレガシーシステムでサービス制御機能を追加したい場合
- HTTP/gRPCプロトコル以外の7層プロトコルサポートは限定的(Aeraki連携で拡張可能)
- Dubboプロトコルを使用する既存システムはAeraki連携で対応可能
新規プロジェクトでの推奨アーキテクチャ:
- HTTP通信にはOpenFeignの採用
- サービスディスカバリにはspring-cloud-starter-kubernetesの利用
- APIゲートウェイにはSpring Cloud Gatewayの導入
リソース定義例
Deployment設定
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-service-v2
labels:
component: user-service
release: v2
spec:
replicas: 2
selector:
matchLabels:
component: user-service
release: v2
template:
metadata:
labels:
component: user-service
release: v2
spec:
serviceAccountName: app-user-service
containers:
- name: app-container
image: user-service:2.1.0
ports:
- containerPort: 8080
Service定義
apiVersion: v1
kind: Service
metadata:
name: user-service
labels:
component: user-service
spec:
ports:
- port: 8080
targetPort: 8080
protocol: TCP
selector:
component: user-service
Gateway設定
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: app-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "app.example.com"
VirtualService設定
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: user-service-vs
spec:
hosts:
- user-service
http:
- route:
- destination:
host: user-service
subset: stable
DestinationRule設定
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: user-service-dr
spec:
host: user-service
subsets:
- name: stable
labels:
release: v2
- name: canary
labels:
release: v3
Kustomizeディレクトリ構造
kustomize-root/
├── project-app-service/
│ ├── base/
│ │ ├── kustomization.yaml
│ │ ├── deployment.yaml
│ │ ├── service.yaml
│ │ ├── gateway.yaml
│ │ ├── virtualservice.yaml
│ │ └── destinationrule.yaml
│ ├── build/
│ │ ├── image-build.yaml
│ │ └── kustomization.yaml
│ └── overlays/
│ └── production/
│ └── kustomization.yaml