Talked at AWS Summit Tokyo 2019 & Developers Summit 2020.
説明つきの動画にてご覧になりたい方はこちらもどうぞ → https://www.youtube.com/watch?v=ZwfdLAClzsc ※ 2019年の動画のためスライドなど多少中身に違いがありますが、だいたい一緒です
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービスメッシュは本当に必要なのか何を解決するのかYasuhiro “Tori” Hara / @toriclsSr. Specialist SA, ContainersAmazon Web Services Japan# d e v s u m i # d e v s u m i BFeb. 14, 2020
View Slide
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Yasuhiro “Tori” Hara / @toriclsSr. Specialist SA, ContainersAmazon Web Services Japan---ERP パッケージベンダー R&D チーム SDE➡ UI ⾃動テスト SaaS➡ クラウド利⽤の SI + MSP にて、コンテナやサーバーレスによる設計・開発・運⽤Web 技術利⽤のゲームやビジネスアプリケーション開発、ML/DL 環境構築運⽤など➡ 現職《 好きな AWS のサービス 》AWS Fargate, AWS Lambda
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Appマイクロサービス化しよう︕
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.“Monolith”マイクロサービス化しよう︕
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.“Monolith”という呼称に込められるニュアンスMonolith
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.“Monolith”という呼称に込められるニュアンス関係者間調整のオーバーヘッドMonolith“Does everything”
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.“Monolith”という呼称に込められるニュアンス関係者間調整のオーバーヘッド変更による影響範囲の広さモジュール構造維持の難しさ Monolith“Does everything”
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.“Monolith”という呼称に込められるニュアンス関係者間調整のオーバーヘッド変更による影響範囲の広さモジュール構造維持の難しさ⾮効率なスケーリングMonolith“Does everything”
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.“Monolith”という呼称に込められるニュアンス関係者間調整のオーバーヘッド変更による影響範囲の広さモジュール構造維持の難しさ⾮効率なスケーリングテスト・ビルドに要する時間の⻑さMonolith“Does everything”
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.マイクロサービス化に期待される効果変更による影響範囲の局所化モジュール境界の維持しやすさ独⽴したデプロイとスケーリング⾃律的なチームによる開発・運⽤Polyglot(-able)“Does one thing”
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.現実世界のモノリスは複雑
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.現実世界のモノリスは複雑...[02/14:14:16:18] ”POST /something" 201 2000ms .......[02/14:14:16:18] ”POST /something" 201 2000ms ....
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.現実世界のモノリスは複雑2.0 sec.時間がかかったのはどこ︖① ALB - アプリ︖② アプリ - S3︖③ アプリ - SQS︖④ アプリ内処理︖➡ AWS X-Ray
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS X-Ray分散アプリケーションの分析と調査のための分散トレーシングサービス• サービス間通信の可視化• エラー原因のサービス発⾒• パフォーマンス上のボトルネック発⾒
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.総処理時間最も時間を要した処理呼び出し順AWS X-Ray分散アプリケーションの分析と調査のための分散トレーシングサービス
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.import com.amazonaws.xray.AWSXRay;import com.amazonaws.xray.AWSXRayRecorderBuilder;...public class WebConfig {...static {AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard().withPlugin(new EC2Plugin()).withPlugin(new ECSPlugin());URL ruleFile = WebConfig.class.getResource("/sampling-rules.json");builder.withSamplingStrategy(new LocalizedSamplingStrategy(ruleFile));AWSXRay.setGlobalRecorder(builder.build());}}AWS X-Ray分散アプリケーションの分析と調査のための分散トレーシングサービス
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.マイクロサービスの課題サービスの適切な分割
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.マイクロサービスの課題サービスの適切な分割テストの難しさ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.マイクロサービスの課題サービスの適切な分割テストの難しさ影響範囲を⾃サービス内に収める難しさ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.マイクロサービスの課題サービスの適切な分割テストの難しさ影響範囲を⾃サービス内に収める難しさサービス間通信の信頼性 - Reliabilityサービス間通信の可観測性 - Observability
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の信頼性- ReliabilityAPIMICROSERVICEMICROSERVICE❔• マイクロサービスは⼀種の分散システム• ネットワーク経由通信 = 失敗が前提• ⼀時的なネットワーク状況による失敗• 対向サービスの不具合・停⽌による失敗• 防御的実装の必要性
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の信頼性を⾼める防御的実装- ReliabilityAPIMICROSERVICEMICROSERVICE1. 呼出先サービスの位置は⼀定ではない→ サービスディスカバリ2. ⼀時的な呼び出しの失敗→ リトライ (w/ Exponential back-off)3. 継続した呼び出しの失敗→ サーキットブレーカー4. 呼出先サービスのパフォーマンス悪化→ タイムアウト5. 呼出システムの不具合→ スロットリング
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の可観測性- Observability• マイクロサービス群 = 1つのシステム• 外形的には「システム」の失敗• 失敗は、どこで、なぜ起きたのか• システムを観測できる実装の必要性APIMICROSERVICEEVENTMICROSERVICEQUEUE OBJECTSTORAGECACHEAPIMICROSERVICEDATABASE
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の可観測性を⾼める実装- Observability• ログ/メトリクス/トレース情報出⼒• 各サービスの既存実装の出⼒フォーマットが不揃いだとコンテキストが⾒えない• 「システム」全体の観測には不向き➡ 全サービスの出⼒フォーマット統⼀APIMICROSERVICEEVENTMICROSERVICEQUEUE OBJECTSTORAGECACHEAPIMICROSERVICEDATABASE
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.全てを実装しきることは可能なのか• 各サービスへの個別実装• 複数の⾔語やフレームワーク• 実装担当者と品質担保⽅法• 統⼀フォーマットの変更• ⼀貫性ある実現⽅法が必要MICROSERVICEAPIAPIMICROSERVICEMICROSERVICEEVENTAPIMICROSERVICEEVENTAPIMICROSERVICEDATABASE DATABASEQUEUE OBJECT STORAGECACHE
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.⼀貫性あるサービス間通信の信頼性/可観測性実装『共通ライブラリ』という解決策アプリケーションコードMICROSERVICE 共通ライブラリü サービスディスカバリü リトライü タイムアウトü スロットリングü etc., etc.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の信頼性と可観測性の実装『共通ライブラリ』という解決策︖アプリケーションコード 共通ライブラリアプリケーション改修が必要…xx⾔語⽤のライブラリがないです共通ライブラリでパフォーマンスが悪化しました先⽇新規開発されたマイクロサービスがライブラリを⼊れてないらしい最新ライブラリに移⾏してくれないチームがいますフォーマット変更したいけど全ライブラリ改修はしたくないyy⾔語 v2 対応はまだですか︖この⾔語書いたことない…
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の信頼性と可観測性の実装共通ライブラリによる実装は⼀貫性の担保が難しいアプリケーションコード 共通ライブラリアプリケーション改修が必要︖このバージョンのときだけクラッシュします共通ライブラリでパフォーマンスが悪化しました先⽇新規開発されたマイクロサービスがライブラリを⼊れてないらしいv2 ライブラリに移⾏してくれないチームがいますフォーマット変更はしたいが全ライブラリ改修はしたくないXX⾔語 v3 対応はまだですか︖こんな⾔語書いたことない…アプリケーションコードMICROSERVICE⼀貫した実装「共通ライブラリ」が密結合を⽣んでしまう
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.プロキシトラフィック アプリケーションサービス間通信の信頼性と可観測性の実現プロキシへのオフロードというアイデア
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービス間通信の信頼性と可観測性の実現プロキシへのオフロードというアイデアA BC D
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.BAサービス間通信の信頼性と可観測性の実装プロキシへのオフロード - サービスメッシュリトライ、タイムアウト、サービスディスカバリ、etc.統⼀フォーマットでのログやメトリクス、トレーシング情報の出⼒
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.OSS プロジェクトコミュニティサポートと多くのインテグレーション多くの本番環境利⽤実績CNCF “Graduated” プロジェクトLyft 社が 2016 年に開始Envoy Proxy
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Envoy proxy の設定Astatic_resources:listeners:- address:socket_address:address: 0.0.0.0port_value: 80# ~ snip ~ #virtual_hosts:- name: backenddomains:- "*"routes:- match:prefix: "/service/1"route:cluster: service1- match:prefix: "/service/2"route:cluster: service2clusters:- name: service1# ~ snip ~ #load_assignment:cluster_name: service1endpoints:- lb_endpoints:- endpoint:address:socket_address:address: service1port_value: 80- name: service2# ~ snip ~ #load_assignment:cluster_name: service2endpoints:- lb_endpoints:- endpoint:address:socket_address:address: service2port_value: 80# ~ snip ~ #
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.プロキシとアプリケーションの密結合異なるライフサイクルとオペレーションモデル§ プロキシを選択した理由は⼀貫性と疎結合性§ ビジネスロジックとしての関⼼(=アプリケーション)§ マイクロサービスとしての関⼼(=システムアーキテクチャ)§ プロキシ設定に設定ファイルを利⽤する§ → 設定変更にデプロイ(と再起動)が必要§ それぞれのライフサイクルとオペレーションモデルは本質的に異なる§ プロキシとアプリケーションが再び密結合に︖
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS App MeshEnvoy proxy の動的設定変更を可能にする
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App Mesh はサービスメッシュのコントロールプレーン• メッシュ全体構造の定義• メッシュを構成するプロキシに対し動的に設定を配信AWS App Meshコントロールプレーン
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS App Meshアプリケーションレベルのネットワークログ・メトリクス・トレース情報の容易な出⼒クライアントサイドのトラフィック・ルーティングポリシークラスタやサービスにまたがるメッシュの構築Amazon ECSAWS FargateAmazon EKSKubernetes on EC2Amazon EC2マネージドコントロールプレーン容易なオペレーション⾼いスケーラビリティ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.トラフィックコントロール• 負荷分散• 重み付け分散• サービスディスカバリ (DNS, AWS Cloud Map)• ヘルスチェック• リトライ• タイムアウト*• サーキットブレーカー*トラフィック管理ルーティング• プロトコルサポート (HTTP, TCP,HTTP2/gRPC)• Path ベース• Header ベース• Cookie ベース• Host ベース*On Roadmap
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.ロギング• HTTP アクセスログ• Amazon CloudWatch Logs• Amazon ECS, Amazon EKS, AWS Fargate におけるコンテナログObservabilityメトリクス• CloudWatch メトリクス• StatsD (with tags)• Prometheus分散トレーシング• AWS X-Ray• Envoy がサポートするその他のトレーシングドライバ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App Mesh - Getting Startedサービス概要https://aws.amazon.com/app-meshドキュメントhttps://docs.aws.amazon.com/app-mesh/index.htmlサンプルアプリケーションhttps://github.com/aws/aws-app-mesh-examplesü AWS App Mesh のご利⽤に追加料⾦は発⽣しませんü 東京リージョンで利⽤可能
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App Mesh - Kubernetes Related ProjectsAWS App Mesh Controller for K8shttps://github.com/aws/aws-app-mesh-controller-for-k8sAWS App Mesh sidecar injector for EKShttps://github.com/aws/aws-app-mesh-injectWeaveworks/Flaggerhttps://flagger.app/
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App Mesh パブリックロードマップhttps://github.com/aws/aws-app-mesh-roadmap/projects/1機能要望、フィードバックもお待ちしております
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.App Mesh パブリックロードマップClient-side load balancingPath-based routingEgress trafficAWS Cloud Map servicediscoveryAWS Cloud Map SD w/selectorsApp Mesh consoleAWS X-Ray tracingEnvoy supported tracingCloudWatch Logs, metricsStatsD, Prometheus metricsAmazon ECS, FargateintegrationAmazon EKS integrationAmazon EC2 integrationAWS PrivateLinkHeader-based routingCookie-based routingHost-based routingRetry policyHTTP2/gRPCEnd-to-end encryption w/ACM(*)Mesh across multi AWSaccounts(*)Near termIngress routingTimeout policymTLSHIPPA eligibilityLonger termCircuit breaker policyAPI Gateway integrationLambda integrationOpen-sourcing App Mesh’s ADSToday*Public preview
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS Container Services パブリックロードマップhttps://github.com/aws/containers-roadmap/projects/1機能要望、フィードバックもお待ちしております
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.• サービスメッシュ• サービス間通信の信頼性と可観測性を確保する⼀貫性ある⼿段の⼀つ• AWS App Mesh• サービスメッシュのマネージドコントロールプレーン• クラスタやサービスにまたがって動的なメッシュを構築できるあなたのシステムにサービスメッシュは必要か
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.• そもそもマイクロサービスにする必然性があるか• コードの品質やテストのなさをモノリスのせいにしていないか• マイクロサービスにしてもこれらが不要になるわけではない• サービスメッシュが解決しないマイクロサービスのデメリットに⽴ち向かう価値があるか• マイクロサービス化により⽣まれる複雑性は対価に⾒合うのか• API 仕様だけを信頼し、相互に実装していく組織に変⾰できるか• API の後⽅互換性を保つ強い意志を持てるかあなたのシステムにサービスメッシュは必要か
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.• 本当にサービスメッシュか• X-Ray の分散トレーシング• ALB(Application Load Balancer) のトラフィックコントロール• AWS CodeDeploy の Blue/Green・カナリーデプロイ• OSS ライブラリの利⽤で⼗分低コストなケース• 動的なサービスメッシュは必要なのか• 静的設定ファイルを利⽤し、Envoy を高機能プロキシとして利⽤するあなたのシステムにサービスメッシュは必要か課題に対する必要性を検討する
Thank you!© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Yasuhiro “Tori” Hara[email protected]toricls