Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ところで、コンテナ化ってどうすればいいの︖浅野 佑貴アマゾン ウェブ サービス ジャパン技術統括本部 ソリューションアーキテクト
Twitterハッシュタグ #AWSInnovate
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
本セッションについて
セッションの対象者• Laptop で Docker コンテナを利⽤した経験はあるが、実際のシステムへの適⽤イメージが沸いていない⽅• コンテナを活⽤する事が決まったが、どの様にコンテナイメージを作成すれば良いかイメージが沸いていない⽅
セッションのゴール• ご⾃⾝の既存ワークロードをコンテナ化する為の考え⽅を整理できる様になる• プロダクション環境への適⽤に向けて⼩さなPoCが実施できる様になる
【ご連絡事項】本セッション内容について確認するためのクイズおよび簡単なアンケートがセッションの最後にあります。なおクイズの回答はアンケートとあわせて表⽰されます。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
本セッションについて
• 本セッションで対象としないこと• オーケストレーションツールの⽐較検討
• Amazon ECS or Amazon EKS or K8s on EC2の⽐較• 詳細なツール検討は、オーケストレーションツールに求める要件が整理した後に実施する
ことをお勧めしています
• CI/CDやテストの⾃動化
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
アジェンダイントロダクション
ワークロードのコンテナ化の検討 Step
まとめ
クイズ
© 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.
ワークロードのコンテナ化に向けた検討の Step
• コンテナ化するワークロードを特定しよう• 最初の取り組みは、⼩さな既存システムを対象にすることがお勧め• コンテナ化に向けて、「何を変えるべきか」、「変更の影響」を具体的に把握しやすい
• コンテナ化するコンポーネントを特定しよう
• 利⽤するコンテナ関連ツール・サービスの準備をしよう
• コンテナイメージを作ろう
• オーケストレーションツールを利⽤して deploy しよう• CI / CD環境の整備• アプリケーションの最適化
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AP Server Layer
VPC
DB Server Layer
Web Server Layer
本セッションで想定する仮想マシンベースのワークロードイメージ
• いわゆるWeb3層モデルの構成
• Elastic Load Balancingを利⽤した負荷分散• Application Load balancer を利⽤している
• ステートフルなDBはマネージドサービスを利⽤している
• Amazon Aurora • Amazon RDS
• 各layer(役割)はそれぞれ独⽴に Scale in/out/ up/downを⾏う
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
コンテナ化する コンポーネントの特定
• 1つの仮想サーバには複数のコンテナ化対象のコンポーネントがある• コンテナ化のベストプラクティス : 1 process 1 container• ⼀般的に、1つのサーバ上では"複数種類"のprocessが動作している
• 仮想サーバを コンテナ化する ≠ 1つの Docker イメージで構成する
• アプリケーションのdeployは「複数のコンテナ」を同時に 実施する必要がある
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
コンテナ化する コンポーネントの特定layer(役割)毎に考える
Web Server Layer
AP Server Layer
VPC
DB Server Layer
• http サーバ• Apache httpd Server • nginx
• 監視エージェントや logging プログラムなど補助的なアプリケーションも動作
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
コンテナ化する コンポーネントの特定deploy する単位を考える• layer毎に「複数のコンテナ」を同時に deploy
• layer内のコンテナに関する設定は共通化する• 各コンテナに割り当てるするCPU/メモリリソースの設定• downstreamへの 接続エンドポイント・認証情報
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
コンテナ化する コンポーネントの特定scaling する単位を考える• VM モデルの場合 ︓仮想サーバ単位で scalingする• コンテナモデルの場合︓「複数のコンテナの固まり」で scalingする
Web Server Layer
AP Server Layer
Web Server Layer
AP Server Layer
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Web / AP Server Layer
Web/AP が同居するパターンの場合• nginx + php-fpmを利⽤している場合の構成例• ⽔平 scaling する layerが1つな為、layer間の連携がシンプルになる
VPC
DB Server Layer
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ここまでのまとめ
• Web システムにおける仮想サーバモデルから出発して、コンテナ化するコンポーネントを整理しました• 仮想サーバを コンテナ化する ≠ 1つの Docker イメージで構成する• アプリケーションのデプロイは「複数のコンテナ」を同時に 実施する必要がある
• 次のStepで整理していくこと• 「複数のコンテナの固まり」を オーケストレーションツールでどの様に表現するか• 「複数のコンテナの固まり」の Deploy をオーケストレーションツールでどの様に表現するか
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS のコンテナサービス
オーケストレーションコンテナのデプロイ、スケジューリング、スケーリング
イメージレジストリコンテナイメージの格納
ホスティングコンテナ実⾏環境
Amazon EC2
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
はじめてのコンテナワークロードにオススメのAWS のコンテナサービス
オーケストレーションコンテナのデプロイ、スケジューリング、スケーリング
イメージレジストリコンテナイメージの格納
ホスティングコンテナ実⾏環境
Amazon EC2
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
運⽤についての検討事項を減らしつつ、少ない学習量で利⽤開始できる
はじめてのコンテナワークロードにオススメのAWS のコンテナサービス
§ AWS がお客様に代わってコンテナ実⾏環境の仮想マシンを管理・運⽤§ コンテナネイティブな実⾏環境を提供
• コンテナを本番環境で利⽤するための AWS ネイティブなオーケストレータ
• ⾼可⽤かつスケーラブルなプライベートイメージレジストリ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon ECS / AWS Fargate アーキテクチャの整理最初に抑える3つの概念
Task(定義)
Service(定義)
Cluster
アプリケーションを構成する1つ以上のコンテナ群(を定義したもの)
Taskを維持・戦略に基づきスケジュールする(設定を定義したもの)
Task または Serviceの論理グループ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
これまで整理した考え⽅と対応させる
「複数のコンテナの固まり」 + コンテナに関する設定 => Task 定義「複数のコンテナの固まり」の数を維持する設定 => Service 定義
Web Server Layer
AP Server Layer
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ツール・サービスが提供する機能の利⽤を検討する
• ロギング• ログを 標準出⼒/エラー出⼒に出⼒すれば、CloudWatch Logs に⾃動で出⼒される• ログを 標準出⼒/エラー出⼒に出⼒することはベストプラクティスの1つ
• モニタリング• CloudWatch Container Insights / CloudWatch Logs Insights を利⽤すれば、Task やコンテナ
レベルでメトリクス・ログを取得可能• 監視エージェントコンテナが不要になる場合も
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ツール・サービスが提供する機能を利⽤するツール・サービスの機能を利⽤することで、構成をシンプルにすることが可能
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ここまでのまとめ
• Amazon ECS / AWS Fargate の組み合わせにおいて、サービス固有の概念との対応⽅針を整理しました• 「複数のコンテナの固まり」 + コンテナに関する設定 => Task 定義• 「複数のコンテナの固まり」の数を維持する設定 => Service 定義
• ツール・サービスが提供する機能の活⽤ポイントを整理しました• 必要となる要件の整理が出来るまでは、標準的な機能の利⽤がオススメ
• 次の Stepで整理していくこと• オーケストレーションツールを利⽤する前提での、Docker イメージの作り⽅
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
コンテナイメージを作ろうアプリケーションの改修例
• オーケストレーションツールによって コンテナは deploy される
• Dockerコンテナとして必要となる基本的なポイント• サーバアプリケーションをフォアグラウンドで実⾏する• SIGTERMをハンドリング出来る様にする• ログ出⼒に標準出⼒/エラー出⼒を活⽤する
• DBへの接続情報を外部から取得する様にする• RDSの場合であれば、接続エンドポイント、ユーザ・パスワードなど• 環境に依存する設定/認証情報を環境変数などを利⽤して、外部から取得する様に変更する
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Dockerコンテナとして必要となる基本的なポイント
FROM debian:buster-slim
LABEL maintainer="NGINX Docker Maintainers <[email protected]>"
<省略>
# forward request and error logs to docker log collectorRUN ln -sf /dev/stdout /var/log/nginx/access.log ¥
&& ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["nginx", "-g", "daemon off;"]
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
DBへの接続情報を外部から取得する様にする
~~<省略> ~~set_config() {
key="$1"value="$2"var_type="${3:-string}"start="(['¥"])$(sed_escape_lhs "$key")¥2¥s*,"end="¥);"if [ "${key:0:1}" = '$' ]; then
start="^(¥s*)$(sed_escape_lhs "$key")¥s*="end=";"
fised -ri -e "s/($start¥s*).*($end)$/¥1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")¥3/" wp-config.php
}
set_config 'DB_HOST' "$WORDPRESS_DB_HOST"set_config 'DB_USER' "$WORDPRESS_DB_USER"set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
~~<省略> ~~
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ここまでのまとめ
• Docker イメージを作成する際の基本ポイントを整理しました• サーバアプリケーションをフォアグラウンドで実⾏する• SIGTERMをハンドリング出来る様にする• ログ出⼒に標準出⼒/エラー出⼒を活⽤する
• 最後の Stepは Amazon ECS / AWS Fargateを利⽤して deploy︕• Task 定義、Service 定義の作成• IAM ロール等の関連リソースの作成
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
まとめ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
まとめ
• Web システムにおける仮想サーバモデルから出発して、ワークロードのコンテナ化の検討 Step を整理しました• コンテナ化するコンポーネントの特定しよう• 利⽤するコンテナ関連ツール・サービスの準備をしよう• コンテナイメージを作ろう• オーケストレーションツールを利⽤して Deploy しよう
• Amazon ECS / AWS Fargate の使い⽅を学び、実際にワークロードをdeployしてみましょう
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
お役⽴ちリンク
コンテナワークロードの基本から振り返りたい⽅
はじめてのコンテナワークロード Part 1 - コンテナの特徴を技術的背景から理解するhttps://d1.awsstatic.com/webinars/jp/pdf/services/201910_AWSInnovate_Container-Think-it-as-containers-they-are-not-virtual-machines-part1.pdf
はじめてのコンテナワークロード Part 2 - 仮想マシン時代とコンテナ時代の考え⽅の違いを理解するhttps://d1.awsstatic.com/webinars/jp/pdf/services/201910_AWSInnovate_Container-Think-it-as-containers-they-are-not-virtual-machines-part2.pdf
はじめてのコンテナワークロード Part 3 - 仮想マシンからの移⾏を成功させるhttps://d1.awsstatic.com/webinars/jp/pdf/services/201910_AWSInnovate_Container-Think-it-as-containers-they-are-not-virtual-machines-part3.pdf
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
コンテナ関連セッションのご紹介
2 2 ,, 0 00 .
����� ���������
W
S SI A S I
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
�� AWS ��������������������� ��������������
$���� ����������� "!#��������������
Twitter����� #AWSInnovate
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
クイズ
Q1: 本セッションのモデルは WebサーバとAPサーバを別 layerと定義し、それぞれ個別にsclaeする前提で話を進めてきました。仮に、AP Server layerがスケールする場合、Web Server Layer側で考慮しないといけない事があります。それはどの様なものでしょうか。
Q2: Q1の回答内容はコンテナワークロードの特有の事象でしょうか。仮想サーバモデルにおいても発⽣する事象でしょうか。
Thank you!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Yuki [email protected]