Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ECS Service Connect で ECS 上のマイクロサービスの耐障害性と可観測性を高めよう

ECS Service Connect で ECS 上のマイクロサービスの耐障害性と可観測性を高めよう

AWS Summit 2023での登壇内容です。
https://aws.amazon.com/jp/summits/tokyo-2023/

kashinoki38 - Yasuhiro Horiuchi

September 01, 2023
Tweet

More Decks by kashinoki38 - Yasuhiro Horiuchi

Other Decks in Technology

Transcript

  1. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ECS Service Connect で ECS 上のマイクロサービスの耐障害性と 可観測性を高めよう 堀内 保大 A W S - 2 4 アマゾン ウェブ サービス ジャパン合同会社 技術統括本部 インターネットメディアソリューショングループ ソリューションアーキテクト
  2. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 自己紹介 堀内 保大 (Yasuhiro Horiuchi) AWS ソリューションアーキテクト • 主にEC系のお客様を担当 • コンテナ技術支援や登壇 バックグラウンド • SIer でシステムへの性能関連の技術支援 (性能試験、監視、チューニング、非機能設計 etc.) 好きなAWSサービス • AWS Fargate @ka_shino_ki 3
  3. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. はじめに 本セッションの対象となる方 • コンテナや Amazon Elastic Container Service (Amazon ECS) について概要を理解 している • Amazon ECS 上でマイクロサービスを構築したいと思っている方 • Amazon ECS における耐障害性や可観測性の確保に興味のある方 本セッションのゴール • Amazon ECS におけるサービス間通信の課題、実現の選択肢を理解いただく • Amazon ECS Service Connect のユースケースやメリットを理解いただく 4
  4. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 1. コンテナとAWSのコンテナサービスのメリット振り返り 2. マイクロサービスとサービス間通信の課題や実現方法 3. Amazon ECS Service Connect 概要 4. Amazon ECS Service Connect Dive Deep 5. まとめ アジェンダ 5
  5. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. コンテナとAWSのコンテナサービスの メリット振り返り
  6. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 企業がコンテナサービスを採用する背景 運用優秀性と セキュリティ スピードとアジリティ 新規アプリの開発に要する時間の短縮 市場投入までの時間の短縮 耐障害性/可用性、セキュリティ強化 コスト インフラコスト、運用工数の削減 7
  7. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. コンテナが実現すること ローカルPC ステージング / QA 本番 パッケージングされたアプリケーション (コンテナ) 8 ランタイム ソースコード ライブラリ
  8. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. コンテナがもたらすメリット ▪ コンテナの特性を活かすことで次のような効果が期待できる ✓ アプリケーションの可搬性 ✓ 複数環境にわたる一貫した実行可能性 ✓ 高速な開発とリリースサイクルの実現 9
  9. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サーバーレスファーストでよりシンプルにコンテナを実行 サーバーレスファースト 高い抽象化 インフラ管理工数の低減 アプリケーション開発に注力 AWS Fargate & Amazon ECS 10
  10. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. マイクロサービスと サービス間通信の課題や実現方法
  11. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. マイクロサービスによる開発アジリティの向上 • 独立した複数のサービスでソフトウェアを構成する ▪ ビジネスドメインごとにサービスを分割し疎結合にする ▪ 各サービス毎に独立したデプロイが可能となり、 開発アジリティが向上する • アプリケーションが複数のサービスの協調動作によって 実現される世界 → サービス間の通信が必要 12
  12. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービス間通信の信頼性を高める工夫 1. 耐障害性 マイクロサービスは一種の分散システム 1. NWのエラーや遅延、呼出先の不具合/ 停止に対する耐障害性の仕組み • 呼出先サービスの位置は一定でない →サービスディスカバリ • 一時的な呼び出しの失敗 →リトライ(Exponential back-off)、外れ値検知 • 継続した呼び出しの失敗 →サーキットブレーカー • 呼出先サービスのパフォーマンス悪化 →タイムアウト 呼出元サービス 呼出先サービス 13
  13. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービス間通信の信頼性を高める工夫 2. 可観測性 マイクロサービスは一種の分散システム 2. どこで何が起きたのか、なぜ起きたのか 調査するために、可観測性を高める仕組み 各サービスの • メトリクス • ログ • トレース etc. 呼出元サービス 呼出先サービス レイテンシ, エラー数, リクエストレート 14
  14. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービス間通信におけるメトリクス監視の観点 サービス監視(RED) ▪Rate : 秒間リクエスト数, 秒間PV数 ▪Error Rate : エラー率, レスポンスコード数 ▪Duration : Response Time 15
  15. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. これまでのサービス間通信の選択肢 • ロードバランサー有 1. Elastic Load Balancing (ELB) • ロードバランサー無 2. Amazon ECS service discovery 3. AWS App Mesh 16
  16. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. メリット • さまざまな機能セット E.g. ヘルスチェック • トラフィックのメトリクス 考慮点 • 追加のインフラストラクチャ • ネットワークレイテンシーの増加 • ヘルスチェックに依存 1. Elastic Load Balancing (ELB) の利用 Amazon ECS サービス Amazon ECS コントロールプレーン タスク ELB 呼出元サービス Request Request 登録 17 Amazon ECS サービス タスク 呼出先サービス ...
  17. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Query メリット • クライアントが対向サービスと 直接通信 • 少数のシステムコンポーネント 考慮点 • 以下は含まれない • 信頼性を保つ通信制御 E.g. リトライ、外れ値検知 etc • トラフィックのメトリクス取得 2. Amazon ECS service discovery の利用 タスク Amazon ECS コントロールプレーン AWS Cloud Map Amazon Route 53 登録 登録 Amazon ECS サービス Request 18 呼出元サービス Amazon ECS サービス タスク 呼出先サービス ...
  18. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. メリット • きめ細かいトラフィックの制御 E.g. リトライ、外れ値検知、 サーキットブレーカー、タイムアウト • トラフィックの豊富な可観測性 E.g. メトリクス、ログ、トレース 考慮点 • 追加のコンポーネントの管理が必要 • 柔軟性に伴う複雑性 3. AWS App Mesh の利用 Request Amazon ECS コントロールプレーン AWS Cloud Map 登録 AWS App Mesh コントロールプレーン Amazon ECS サービス 19 呼出元サービス タスク 呼出先サービス envoy App コンテナ タスク . . envoy App コンテナ Amazon ECS サービス 動的設定
  19. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. どの選択肢も一長一短 信頼性を保つための工夫【再掲】 1. ネットワークのエラーや遅延、呼出先のダウンに対する耐障害性の 仕組みの考慮が必要 (E.g. リトライ、外れ値検知 etc) 2. サービス毎の可観測性を高めることでトラブルシューティングを容易 にする工夫が重要 耐障害性と可観測性がシンプルに組み込まれた選択肢が欲しい 20
  20. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon ECS Service Connect !!!
  21. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon ECS Service Connect サービスメッシュと Service Discovery の両方を提供 Amazon ECS Service Connect サービスの デプロイ サービス間の 接続 メトリクス の取得 アプリケーション の定義 22
  22. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect の仕組み Amazon ECS コントロールプレーン AWS Cloud Map App コンテナ クライアント 呼出元サービス Service Connect プロキシ ELB 23 Amazon ECS サービス 登録 タスク App コンテナ 呼出先サービス Amazon ECS サービス タスク Service Connect プロキシ Agent Envoy Agent Envoy
  23. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect の特徴 サービス間通信における考慮事項が追加設定なしに組み込まれる 1. 耐障害性(リトライ、外れ値検知、タイムアウト) 2. 可観測性(サービス間のトラフィックメトリクスの収集) 3. 堅牢なデプロイ(ローリングアップデートへの対応) 24
  24. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect の利用料金 25 Service Connect プロキシが利用する分
  25. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Service Connect Dive Deep 1. 耐障害性 2. 可観測性 3. 堅牢なデプロイ
  26. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect のメリット 1. 耐障害性 • 設定なしにサービス間通信に対して耐障害性の仕組みが入る 1. 自動リトライ • NW障害や503エラー時に、Proxyレイヤで別タスクに自動リトライ 2. 外れ値検知 • リクエストエラーが連続した場合、ルーティングから一定期間除外 3. 接続タイムアウト 27 ※2023年4月時点
  27. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 耐障害性の高いサービス間通信の実現– 1 自動リトライ 呼出元サービス 呼出先サービス NW障害や503エラー時に、Proxyレイヤで別タスクに自動リトライ App コンテナ Service Connect プロキシ Agent Envoy タスク タスク タスク Amazon ECS サービス Amazon ECS サービス タスク 28
  28. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 耐障害性の高いサービス間通信の実現– 1 自動リトライ 呼出元サービス 呼出先サービス App コンテナ Service Connect プロキシ Agent Envoy タスク タスク タスク Amazon ECS サービス Amazon ECS サービス タスク 29 エラーが見えない ←突如ダウン NW障害や503エラー時に、Proxyレイヤで別タスクに自動リトライ
  29. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 耐障害性の高いサービス間通信の実現– 2 外れ値検知 呼出元サービス 呼出先サービス App コンテナ Service Connect プロキシ Agent Envoy タスク タスク タスク Amazon ECS サービス Amazon ECS サービス タスク 30 ←継続的にエラー リクエストエラーが連続した場合、ルーティングから一定期間除外
  30. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 耐障害性の高いサービス間通信の実現– 2 外れ値検知 呼出元サービス 呼出先サービス App コンテナ Service Connect プロキシ Agent Envoy タスク タスク タスク Amazon ECS サービス Amazon ECS サービス タスク 31 ←継続的にエラー リクエストエラーが連続した場合、ルーティングから一定期間除外
  31. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect のメリット 2. 可観測性 Service Connect プロキシが収集するリクエストに関するCloudWatch メトリクスが利用可能 1. 自サービスに対するリクエスト関連 – コネクション数(新規、アクティブ) – リクエスト数 etc. 2. 呼出先サービスに対するリクエスト関連 – 呼出先サービス毎のリクエストカウント – レスポンスコード毎のレスポンス数 – 呼出先サービス毎のレスポンスタイム etc. 32 呼出元サービス 呼出先サービス
  32. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービス間通信におけるメトリクス監視の観点 【再掲】 サービス監視(RED) ▪Rate : 秒間リクエスト数, 秒間PV数 ▪Error Rate : エラー率, レスポンスコード数 ▪Duration : Response Time 33
  33. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect のメリット 2. 可観測性 • Service Connect プロキシが収集するリクエストに関するCloudWatch メトリクス 1. 自サービスに対するリクエスト関連 – コネクション数(新規、アクティブ) – リクエスト数 etc. 2. 呼出先サービスに対するリクエスト関連 – 呼出先サービス毎のリクエストカウント – レスポンスコード毎のレスポンス数 – 呼出先サービス毎のレスポンスタイム etc. 34 ←Rate ←Error Rate ←Duration
  34. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect のメリット 3. 堅牢なデプロイ • Amazon ECS のローリングアップデートをサポート • コネクションドレイニングによるダウンタイム無しのデプロイ • Cloud Mapを利用することでDNS TTLの影響を受けない高速なデプロイ 35
  35. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 堅牢なデプロイメント Amazon ECS コントロールプレーン 36 呼出元サービス App コンテナ Service Connect プロキシ Agent Envoy タスク Amazon ECS サービス ローリング アップデート 呼出先サービス タスク タスク Amazon ECS サービス タスク v1 v1 v1 ←コネクション ドレーニング タスク v2 コネクションドレイニングによるダウンタイム無しのデプロイ ←v2起動開始 AWS Cloud Map 登録解除
  36. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. これからのサービス間通信の選択肢 37 • ロードバランサー有 1. Elastic Load Balancing (ELB) • ロードバランサー無 2. Amazon ECS service discovery 3. AWS App Mesh
  37. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. これからのサービス間通信の選択肢 38 • ロードバランサー有 1. Elastic Load Balancing (ELB) • ロードバランサー無 2. Amazon ECS service discovery 3. AWS App Mesh 4. Amazon ECS Service Connect [new] ←サービス間通信で信頼性を重視する 場合のファーストプライオリティ ←細かい通信制御の要件(e.g. 各種設定の閾値変更) がある場合 ←外部からアクセスさせたい、 B/Gデプロイを利用したい場合 ←プロキシを利用せずに個別実装で 信頼性を導入する場合
  38. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. まとめ
  39. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Key Takeaway 1. サービス間通信では耐障害性と可観測性の実装が重要 2. Amazon ECSにおけるサービス間通信の実装方法は、 これまで 1. ELB / 2. Service Discovery / 3. AWS App Mesh の3通り 3. 4つ目の選択肢として、Amazon ECS Service Connect が登場 ▪ Service Connect プロキシがサイドカーコンテナとして注入される 40
  40. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Key Takeaway 4. Service Connect により、シンプルな設定で高い信頼性を 持ったサービス間通信を実現できる ▪ 耐障害性:1. 自動リトライ / 2. 外れ値検知 / 3. 接続タイムアウト ▪ 可観測性:サービス間の RED メトリクス ▪ 堅牢なデプロイ:ダウンタイム無しのデプロイメント 41
  41. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Service Connect 学習用コンテンツ • Workshop(日本語) ▪ https://catalog.workshops.aws/ecs-service-connect/ja-JP • AWS 公式ブログ ▪ ローンチブログ: https://aws.amazon.com/jp/blogs/aws/new-amazon-ecs-service-connect-enabling-easy-communication-between- microservices/ ▪ Service Discovery からの移行: https://aws.amazon.com/jp/blogs/containers/migrate-existing-amazon-ecs-services-from-service-discovery-to-amazon-ecs-service- connect/ • Youtube(英語) ▪ re:Invent 2022: https://www.youtube.com/watch?v=1_YUmq3MpYQ ▪ Containers from the Couch: https://www.youtube.com/watch?v=n6ghmEEjpNQ • ドキュメント ▪ https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html 42
  42. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Thank you! © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 堀内 保大 アマゾン ウェブ サービス ジャパン合同会社 技術統括本部 インターネットメディアソリューショングループ ソリューションアーキテクト @ka_shino_ki