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

Yak shaving を避けながら AWS Fargateを使った話 / AWS Fargate without Yak shaving

optim
October 24, 2019

Yak shaving を避けながら AWS Fargateを使った話 / AWS Fargate without Yak shaving

optim

October 24, 2019
Tweet

More Decks by optim

Other Decks in Programming

Transcript

  1. Copyright © OPTiM Corp. All Right Reserved. Yak shaving を避けながら

    AWS Fargateを使った話 Oct 24, 2019 株式会社 オプティム Takahashi
  2. Copyright © OPTiM Corp. All Right Reserved. 2  高橋(Takahashi)

    プラットフォーム事業部 DXユニット マネージャー  SNS • Twitter:@yukey1031(ukitiyan) • Github:@ukitiyan • SlideShare: @ukitiyan(https://www.slideshare.net/ukitiyan) • Qiita: @ukitiyan(https://qiita.com/ukitiyan)  備考 • 2018/09 OPTiM入社(無事に1年経過!) • 好きなCIOSサービス:Messaging • Javaとサーバーレスを好む • 過去にマギーと呼ばれていた
  3. Copyright © OPTiM Corp. All Right Reserved. 8 シナリオ(仮定) CIOSを活用しながらも

    アプリのみ AWSにデプロイするDX案件 (期間限定だけど今すぐに) というシナリオ
  4. Copyright © OPTiM Corp. All Right Reserved. 9 構成 Cloud

    IoT OS ( CIOS ) App App App IdM App Cluster App App Messaging (Pub/Sub) FileStorage Streaming ここだけ AWSに Appは 若いメンバーが実装
  5. Copyright © OPTiM Corp. All Right Reserved. 10 構成 Cloud

    IoT OS ( CIOS ) App App App IdM App App Messaging (Pub/Sub) FileStorage Streaming AWSに Appをデプロイ
  6. Copyright © OPTiM Corp. All Right Reserved. 11  Java,

    Vue.js, PHP... で実装されたマイクロサービス前提のAppのデプロイに対 応する。  CIOSとの親和性は残したまま、本件に伴うApp カスタマイズは極力行わない。  一時的な公開となるため、極力サーバー運用に手を掛けない。  基本的にこの周辺は自分が行う。 • 若いメンバーはApp実装しながら、私の行動を見つめている。という妄想。。 考える事
  7. Copyright © OPTiM Corp. All Right Reserved. 13 AWS構成 VPC

    Availability Zone Availability Zone Public subnet Bastion Public subnet Private subnet Private subnet DT Web Sub App WebAPI Video Server DT App DB subnet DB subnet Ras Front
  8. Copyright © OPTiM Corp. All Right Reserved. 18 AWS SamplesのCFテンプレートを活用

    Amazon ECSおよびAWS CloudFormation(YAML)で コンテナー化されたマイクロサービスをデプロイするための リファレンスアーキテクチャ(Not Fargate)
  9. Copyright © OPTiM Corp. All Right Reserved. 19  Fargateに対応する。

     今回App用のServiceとAWSWaf, Bastion, RDS, S3等各種InfrastructureのCFテンプ レートをネストで実装する。 (AutoScalingも必要に応じて設定  BastionのCloud-InitでDDL, DMLの実行をする。  マイクロサービスに対応するために、ECS ServiceDiscovery、TaskRoleへの AWSXRayDaemonWriteAccessと各TaskへのxrayデーモンのサイドカーをCFテンプ レートに実装する。  既存のパイプラインを使いAppのDockerImageは所定のECRにプッシュされる前提。 対応事項 参照:
  10. Copyright © OPTiM Corp. All Right Reserved. 20  aws

    cloudformation create-stackコマンドでデプロイ実行。 環境構築 stack起動 20分 シュっと完成!!
  11. Copyright © OPTiM Corp. All Right Reserved. 23 Amazon ECS

    Service Discovery https://aws.amazon.com/jp/blogs/news/amazon-ecs-service-discovery/ App Mesh とは 統合しない
  12. Copyright © OPTiM Corp. All Right Reserved. 24 ECS Service

    Discovery Amazon Route 53 Hosted zone ECS(ServiceDiscovery) ECSServiceDiscoveryNamespace: Type: AWS::ServiceDiscovery::PrivateDnsNamespace Properties: Vpc: !Ref VPC Name: "showroom.local" Resources: ServiceDiscoveryRecord: Type: "AWS::ServiceDiscovery::Service" Properties: Name: ”dt-app” DnsConfig: NamespaceId: !Ref ECSServiceDiscoveryNamespace Route table showroom.local dt-app.showroom.local  PrivateDNSにAレコードが追加され対象サービス に自動紐づけ
  13. Copyright © OPTiM Corp. All Right Reserved. 26 AWS X-Ray

    https://docs.aws.amazon.com/ja_jp/xray/latest/devguide/aws-xray.html App Meshは使わない
  14. Copyright © OPTiM Corp. All Right Reserved. 27 X-Ray AWS

    X-Ray Task App x-ray-demon <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-xray-recorder-sdk-spring</artifactId> <version>2.3.0</version> </dependency> @Aspect @Component public class XRayInspector extends AbstractXRayInterceptor { ... } e.g. Spring Appの場合 抜 粋
  15. Copyright © OPTiM Corp. All Right Reserved. 29 Amazon ECS

    Container Insights 因みに、CF未対応
  16. Copyright © OPTiM Corp. All Right Reserved. 30 Amazon ECS

    Container Insights  現在、AWS CloudFormation を使用して新しいクラスターを作成する場合、Container Insights を有効にすることはできません。  深追いせずに、AWS CLI のバージョン 1.16.200 以降で以下2コマンドで有効にする。 $ aws ecs put-account-setting --name "containerInsights" --value "enabled" $ aws ecs update-cluster-settings --cluster showroom ¥ --settings name=containerInsights,value=enabled
  17. Copyright © OPTiM Corp. All Right Reserved. 33 kayac/ecspresso 

    面白法人カヤックさん から提供されているGo製のECSデプロイツール。  CloudFormationでのサービスのデプロイも可能だが、副次的に他サービス が更新されるリスクがあるため、サービス単体でデプロイ可能は幸せ。  AWS CLIのラッパーのため、CFでサポートされていないAPI(例えば FireLens)等の対応が先行する。 $ ecspresso init --region ap-northeast-1 --cluster rasshowroom ¥ --service webapi-service --config webapi.yaml $ ls ecs-service-def.json ecs-task-def.json webapi.yaml $ ecspresso deploy --config webapi.yaml ・init して deploy するだけでサービスの更新