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

サービスメッシュは本当に必要なのか、何を解決するのか / Service meshes - Do we really need them? What problems do they solve?

Tori Hara
PRO
February 14, 2020

サービスメッシュは本当に必要なのか、何を解決するのか / Service meshes - Do we really need them? What problems do they solve?

Talked at AWS Summit Tokyo 2019 & Developers Summit 2020.

説明つきの動画にてご覧になりたい方はこちらもどうぞ
https://www.youtube.com/watch?v=ZwfdLAClzsc
※ 2019年の動画のためスライドなど多少中身に違いがありますが、だいたい一緒です

Tori Hara
PRO

February 14, 2020
Tweet

More Decks by Tori Hara

Other Decks in Technology

Transcript

  1. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービスメッシュは本当に必要なのか
    何を解決するのか
    Yasuhiro “Tori” Hara / @toricls
    Sr. Specialist SA, Containers
    Amazon Web Services Japan
    # d e v s u m i # d e v s u m i B
    Feb. 14, 2020

    View Slide

  2. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Yasuhiro “Tori” Hara / @toricls
    Sr. Specialist SA, Containers
    Amazon Web Services Japan
    ---
    ERP パッケージベンダー R&D チーム SDE
    ➡ UI ⾃動テスト SaaS
    ➡ クラウド利⽤の SI + MSP にて、コンテナやサーバーレスによる設計・開発・運⽤
    Web 技術利⽤のゲームやビジネスアプリケーション開発、ML/DL 環境構築運⽤など
    ➡ 現職
    《 好きな AWS のサービス 》AWS Fargate, AWS Lambda

    View Slide

  3. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App

    View Slide

  4. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App





    View Slide

  5. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App
    マイクロ
    サービス化
    しよう︕






    View Slide

  6. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    “Monolith”
    マイクロ
    サービス化
    しよう︕






    View Slide

  7. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    “Monolith”という呼称に込められるニュアンス
    Monolith

    View Slide

  8. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    “Monolith”という呼称に込められるニュアンス
    関係者間調整のオーバーヘッド
    Monolith
    “Does everything”

    View Slide

  9. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    “Monolith”という呼称に込められるニュアンス
    関係者間調整のオーバーヘッド
    変更による影響範囲の広さ
    モジュール構造維持の難しさ Monolith
    “Does everything”

    View Slide

  10. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    “Monolith”という呼称に込められるニュアンス
    関係者間調整のオーバーヘッド
    変更による影響範囲の広さ
    モジュール構造維持の難しさ
    ⾮効率なスケーリング
    Monolith
    “Does everything”

    View Slide

  11. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    “Monolith”という呼称に込められるニュアンス
    関係者間調整のオーバーヘッド
    変更による影響範囲の広さ
    モジュール構造維持の難しさ
    ⾮効率なスケーリング
    テスト・ビルドに要する時間の⻑さ
    Monolith
    “Does everything”

    View Slide

  12. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    マイクロサービス化に期待される効果
    変更による影響範囲の局所化
    モジュール境界の維持しやすさ
    独⽴したデプロイとスケーリング
    ⾃律的なチームによる開発・運⽤
    Polyglot(-able)
    “Does one thing”

    View Slide

  13. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  14. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App

    View Slide

  15. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  16. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    現実世界のモノリスは複雑

    View Slide

  17. © 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 .
    .
    .
    .

    View Slide

  18. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    現実世界のモノリスは複雑
    2.0 sec.
    時間がかかったのはどこ︖
    ① ALB - アプリ︖
    ② アプリ - S3︖
    ③ アプリ - SQS︖
    ④ アプリ内処理︖
    ➡ AWS X-Ray

    View Slide

  19. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    AWS X-Ray
    分散アプリケーションの分析と調査のための分散トレーシングサービス
    • サービス間通信の可視化
    • エラー原因のサービス発⾒
    • パフォーマンス上のボトル
    ネック発⾒

    View Slide

  20. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    総処理時間
    最も時間を要した処理
    呼び出し順
    AWS X-Ray
    分散アプリケーションの分析と調査のための分散トレーシングサービス

    View Slide

  21. © 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
    分散アプリケーションの分析と調査のための分散トレーシングサービス

    View Slide

  22. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  23. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  24. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    マイクロサービスの課題
    サービスの適切な分割

    View Slide

  25. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    マイクロサービスの課題
    サービスの適切な分割
    テストの難しさ

    View Slide

  26. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    マイクロサービスの課題
    サービスの適切な分割
    テストの難しさ
    影響範囲を⾃サービス内に収める難しさ

    View Slide

  27. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    マイクロサービスの課題
    サービスの適切な分割
    テストの難しさ
    影響範囲を⾃サービス内に収める難しさ
    サービス間通信の信頼性 - Reliability
    サービス間通信の可観測性 - Observability

    View Slide

  28. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の信頼性- Reliability
    API
    MICROSERVICE
    MICROSERVICE

    • マイクロサービスは⼀種の分散システム
    • ネットワーク経由通信 = 失敗が前提
    • ⼀時的なネットワーク状況による失敗
    • 対向サービスの不具合・停⽌による失敗
    • 防御的実装の必要性

    View Slide

  29. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の信頼性を⾼める防御的実装- Reliability
    API
    MICROSERVICE
    MICROSERVICE

    1. 呼出先サービスの位置は⼀定ではない
    → サービスディスカバリ
    2. ⼀時的な呼び出しの失敗
    → リトライ (w/ Exponential back-off)
    3. 継続した呼び出しの失敗
    → サーキットブレーカー
    4. 呼出先サービスのパフォーマンス悪化
    → タイムアウト
    5. 呼出システムの不具合
    → スロットリング

    View Slide

  30. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の可観測性- Observability
    • マイクロサービス群 = 1つのシステム
    • 外形的には「システム」の失敗
    • 失敗は、どこで、なぜ起きたのか
    • システムを観測できる実装の必要性
    API
    MICROSERVICE
    EVENT
    MICROSERVICE
    QUEUE OBJECT
    STORAGE
    CACHE
    API
    MICROSERVICE
    DATABASE

    View Slide

  31. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の可観測性を⾼める実装- Observability
    • ログ/メトリクス/トレース情報出⼒
    • 各サービスの既存実装の出⼒フォー
    マットが不揃いだとコンテキストが
    ⾒えない
    • 「システム」全体の観測には不向き
    ➡ 全サービスの出⼒フォーマット統⼀
    API
    MICROSERVICE
    EVENT
    MICROSERVICE
    QUEUE OBJECT
    STORAGE
    CACHE
    API
    MICROSERVICE
    DATABASE

    View Slide

  32. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    全てを実装しきることは可能なのか
    • 各サービスへの個別実装
    • 複数の⾔語やフレームワーク
    • 実装担当者と品質担保⽅法
    • 統⼀フォーマットの変更
    • ⼀貫性ある実現⽅法が必要
    MICROSERVICE
    API
    API
    MICROSERVICE
    MICROSERVICE
    EVENT
    API
    MICROSERVICE
    EVENT
    API
    MICROSERVICE
    DATABASE DATABASE
    QUEUE OBJECT STORAGE
    CACHE

    View Slide

  33. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    ⼀貫性あるサービス間通信の信頼性/可観測性実装
    『共通ライブラリ』という解決策
    アプリケーション
    コード
    MICROSERVICE 共通ライブラリ
    ü サービスディスカバリ
    ü リトライ
    ü タイムアウト
    ü スロットリング
    ü etc., etc.

    View Slide

  34. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の信頼性と可観測性の実装
    『共通ライブラリ』という解決策︖
    アプリケーションコード 共通ライブラリ
    アプリケーション
    改修が必要…
    xx⾔語⽤の
    ライブラリがないです
    共通ライブラリで
    パフォーマンスが
    悪化しました
    先⽇新規開発された
    マイクロサービスが
    ライブラリを⼊れて
    ないらしい
    最新ライブラリに
    移⾏してくれない
    チームがいます
    フォーマット変更
    したいけど全ライブラリ
    改修はしたくない
    yy⾔語 v2 対応は
    まだですか︖
    この⾔語
    書いたことない…

    View Slide

  35. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の信頼性と可観測性の実装
    共通ライブラリによる実装は⼀貫性の担保が難しい
    アプリケーションコード 共通ライブラリ
    アプリケーション
    改修が必要︖
    このバージョンの
    ときだけクラッシュ
    します
    共通ライブラリで
    パフォーマンスが
    悪化しました
    先⽇新規開発された
    マイクロサービスが
    ライブラリを⼊れて
    ないらしい
    v2 ライブラリに
    移⾏してくれない
    チームがいます
    フォーマット変更は
    したいが全ライブラリ
    改修はしたくない
    XX⾔語 v3 対応は
    まだですか︖
    こんな⾔語
    書いたことない…
    アプリケーション
    コード
    MICROSERVICE
    ⼀貫した実装「共通ライブラリ」が密結合を⽣んでしまう

    View Slide

  36. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    プロキシ
    トラフィック アプリケーション
    サービス間通信の信頼性と可観測性の実現
    プロキシへのオフロードというアイデア

    View Slide

  37. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    サービス間通信の信頼性と可観測性の実現
    プロキシへのオフロードというアイデア
    A B
    C D

    View Slide

  38. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  39. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    B
    A
    サービス間通信の信頼性と可観測性の実装
    プロキシへのオフロード - サービスメッシュ
    リトライ、
    タイムアウト、
    サービスディスカバ
    リ、
    etc.
    統⼀フォーマットでの
    ログやメトリクス、トレーシング情報の出⼒

    View Slide

  40. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    OSS プロジェクト
    コミュニティサポートと多くのインテグレーション
    多くの本番環境利⽤実績
    CNCF “Graduated” プロジェクト
    Lyft 社が 2016 年に開始
    Envoy Proxy

    View Slide

  41. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Envoy proxy の設定
    A
    static_resources:
    listeners:
    - address:
    socket_address:
    address: 0.0.0.0
    port_value: 80
    # ~ snip ~ #
    virtual_hosts:
    - name: backend
    domains:
    - "*"
    routes:
    - match:
    prefix: "/service/1"
    route:
    cluster: service1
    - match:
    prefix: "/service/2"
    route:
    cluster: service2
    clusters:
    - name: service1
    # ~ snip ~ #
    load_assignment:
    cluster_name: service1
    endpoints:
    - lb_endpoints:
    - endpoint:
    address:
    socket_address:
    address: service1
    port_value: 80
    - name: service2
    # ~ snip ~ #
    load_assignment:
    cluster_name: service2
    endpoints:
    - lb_endpoints:
    - endpoint:
    address:
    socket_address:
    address: service2
    port_value: 80
    # ~ snip ~ #

    View Slide

  42. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    プロキシとアプリケーションの密結合
    異なるライフサイクルとオペレーションモデル
    § プロキシを選択した理由は⼀貫性と疎結合性
    § ビジネスロジックとしての関⼼(=アプリケーション)
    § マイクロサービスとしての関⼼(=システムアーキテクチャ)
    § プロキシ設定に設定ファイルを利⽤する
    § → 設定変更にデプロイ(と再起動)が必要
    § それぞれのライフサイクルとオペレーションモデルは
    本質的に異なる
    § プロキシとアプリケーションが再び密結合に︖

    View Slide

  43. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    AWS App Mesh
    Envoy proxy の動的設定変更を可能にする

    View Slide

  44. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App Mesh はサービスメッシュの
    コントロールプレーン
    • メッシュ全体構造の定義
    • メッシュを構成するプロキシ
    に対し動的に設定を配信
    AWS App Mesh
    コントロール
    プレーン

    View Slide

  45. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    AWS App Mesh
    アプリケーションレベルのネットワーク
    ログ・メトリクス・トレース情報の容易な出⼒
    クライアントサイドのトラフィック・ルーティングポリシー
    クラスタやサービスにまたがるメッシュの構築
    Amazon ECS
    AWS Fargate
    Amazon EKS
    Kubernetes on EC2
    Amazon EC2
    マネージドコントロールプレーン
    容易なオペレーション
    ⾼いスケーラビリティ

    View Slide

  46. © 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

    View Slide

  47. © 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 がサポートするその他のトレーシングドライバ

    View Slide

  48. © 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 のご利⽤に追加料⾦は発⽣しません
    ü 東京リージョンで利⽤可能

    View Slide

  49. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App Mesh - Kubernetes Related Projects
    AWS App Mesh Controller for K8s
    https://github.com/aws/aws-app-mesh-controller-
    for-k8s
    AWS App Mesh sidecar injector for EKS
    https://github.com/aws/aws-app-mesh-inject
    Weaveworks/Flagger
    https://flagger.app/

    View Slide

  50. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App Mesh パブリックロードマップ
    https://github.com/aws/aws-app-mesh-roadmap/projects/1
    機能要望、フィードバックも
    お待ちしております

    View Slide

  51. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    App Mesh パブリックロードマップ
    Client-side load balancing
    Path-based routing
    Egress traffic
    AWS Cloud Map service
    discovery
    AWS Cloud Map SD w/
    selectors
    App Mesh console
    AWS X-Ray tracing
    Envoy supported tracing
    CloudWatch Logs, metrics
    StatsD, Prometheus metrics
    Amazon ECS, Fargate
    integration
    Amazon EKS integration
    Amazon EC2 integration
    AWS PrivateLink
    Header-based routing
    Cookie-based routing
    Host-based routing
    Retry policy
    HTTP2/gRPC
    End-to-end encryption w/
    ACM(*)
    Mesh across multi AWS
    accounts(*)
    Near term
    Ingress routing
    Timeout policy
    mTLS
    HIPPA eligibility
    Longer term
    Circuit breaker policy
    API Gateway integration
    Lambda integration
    Open-sourcing App Mesh’s ADS
    Today
    *Public preview

    View Slide

  52. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    AWS Container Services パブリックロードマップ
    https://github.com/aws/containers-roadmap/projects/1
    機能要望、フィードバックも
    お待ちしております

    View Slide

  53. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  54. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.

    View Slide

  55. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    • サービスメッシュ
    • サービス間通信の信頼性と可観測性を確保する⼀貫性ある⼿段の⼀つ
    • AWS App Mesh
    • サービスメッシュのマネージドコントロールプレーン
    • クラスタやサービスにまたがって動的なメッシュを構築できる
    あなたのシステムにサービスメッシュは必要か

    View Slide

  56. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    • そもそもマイクロサービスにする必然性があるか
    • コードの品質やテストのなさをモノリスのせいにしていないか
    • マイクロサービスにしてもこれらが不要になるわけではない
    • サービスメッシュが解決しないマイクロサービスのデメリットに
    ⽴ち向かう価値があるか
    • マイクロサービス化により⽣まれる複雑性は対価に⾒合うのか
    • API 仕様だけを信頼し、相互に実装していく組織に変⾰できるか
    • API の後⽅互換性を保つ強い意志を持てるか
    あなたのシステムにサービスメッシュは必要か

    View Slide

  57. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    • 本当にサービスメッシュか
    • X-Ray の分散トレーシング
    • ALB(Application Load Balancer) のトラフィックコントロール
    • AWS CodeDeploy の Blue/Green・カナリーデプロイ
    • OSS ライブラリの利⽤で⼗分低コストなケース
    • 動的なサービスメッシュは必要なのか
    • 静的設定ファイルを利⽤し、Envoy を高機能プロキシとして利⽤する
    あなたのシステムにサービスメッシュは必要か
    課題に対する必要性を検討する

    View Slide

  58. Thank you!
    © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    Yasuhiro “Tori” Hara
    [email protected]
    toricls

    View Slide