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

スケジュール指定のFargate Spotと友達になれた話

スケジュール指定のFargate Spotと友達になれた話

荒木 ARK

March 07, 2024
Tweet

More Decks by 荒木 ARK

Other Decks in Technology

Transcript

  1. • • • • アジアパシフィック (東京) Fargate Fargate Spot 割引率

    1 時間あたりの vCPU 単位 0.05056 USD 0.015168 USD 70% 1 時間あたりの GB 単位 0.00553 USD 0.001659 USD 70%
  2. • • 項⽬ 説明 capacity_providers FARGATE or FARGATE_SPOT を指定 base

    最⼩実⾏タスク数 weight タスク数⽐率
  3. • resource "aws_ecs_service" "service" { name = "hoge" cluster =

    aws_ecs_cluster.cluster.id desired_count = 2 - launch_type = "FARGATE" platform_version = "1.4.0" enable_execute_command = true + capacity_provider_strategy { + capacity_provider = "FARGATE" + base = 1 + weight = 0 + } + + capacity_provider_strategy { + capacity_provider = "FARGATE_SPOT" + base = 0 + weight = 1 + } + ・・・略 Terraform will perform the following actions: # aws_ecs_service.service must be replaced -/+ resource "aws_ecs_service" "service" { 〜 略 ~ launch_type = "FARGATE" -> (known after apply) + capacity_provider_strategy { # forces replacement + base = 0 + capacity_provider = "FARGATE_SPOT" + weight = 1 } + capacity_provider_strategy { # forces replacement + base = 1 + capacity_provider = "FARGATE" + weight = 0 } 〜 略 } terrafor plan
  4. • aws ecs update-service ¥ --capacity-provider-strategy capacityProvider=FARGATE,base=1,weight=0 capacityProvider=FARGATE_SPOT,base=0,weight=1 ¥ --cluster

    example-ecs-cluster ¥ --service example-ecs-service ¥ --force-new-deployment resource "aws_ecs_service" "service" { name = "hoge" cluster = aws_ecs_cluster.cluster.id desired_count = 2 - launch_type = "FARGATE" platform_version = "1.4.0" enable_execute_command = true + capacity_provider_strategy { + capacity_provider = "FARGATE" + base = 1 + weight = 0 + } + + capacity_provider_strategy { + capacity_provider = "FARGATE_SPOT" + base = 0 + weight = 1 + } + ・・・略 } No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. terrafor plan
  5. ❯ aws ecs update-service ¥ --capacity-provider-strategy capacityProvider=FARGATE,base=1,weight=0 capacityProvider=FARGATE_SPOT,base=0,weight=1 ¥ --cluster

    xxx-clusster ¥ --service xxx-service ¥ --force-new-deployment An error occurred (InvalidParameterException) when calling the UpdateService operation: Cannot force a new deployment on services with a CODE_DEPLOY deployment controller. Use AWS CodeDeploy to trigger a new deployment. ︕︕︖︖
  6. ❯ aws deploy create-deployment ¥ --application-name xxx ¥ --deployment-group-name yyy

    ¥ --revision '{"revisionType": "AppSpecContent", "appSpecContent": {"content": "{¥"version¥": 0.0, ¥"Resources¥": [{¥"TargetService¥": {¥"Type¥": ¥"AWS::ECS::Service¥", ¥"Properties¥": {¥"TaskDefinition¥": ¥"arn:aws:ecs:ap-northeast-1:123456789012:task-definition/xxx¥", ¥"LoadBalancerInfo¥": {¥"ContainerName¥": ¥"example-api¥", ¥"ContainerPort¥": 8080},¥"CapacityProviderStrategy¥": [{¥"Base¥":0,¥"CapacityProvider¥":¥"FARGATE_SPOT¥",¥"Weight¥":1},{¥"Base¥":0,¥"CapacityProvider¥":¥"FARGATE¥",¥"Weight¥":0}]}}}]} "}}'
  7. ❯ aws deploy create-deployment ¥ --application-name xxx ¥ --deployment-group-name yyy

    ¥ --revision '{"revisionType": "AppSpecContent", "appSpecContent": {"content": "{¥"version¥": 0.0, ¥"Resources¥": [{¥"TargetService¥": {¥"Type¥": ¥"AWS::ECS::Service¥", ¥"Properties¥": {¥"TaskDefinition¥": ¥"arn:aws:ecs:ap-northeast-1:123456789012:task-definition/xxx¥", ¥"LoadBalancerInfo¥": {¥"ContainerName¥": ¥"example-api¥", ¥"ContainerPort¥": 8080},¥"CapacityProviderStrategy¥": [{¥"Base¥":0,¥"CapacityProvider¥":¥"FARGATE_SPOT¥",¥"Weight¥":1},{¥"Base¥":0,¥"CapacityProvider¥":¥"FARGATE¥",¥"Weight¥":0}]}}}]} "}}’ { "deploymentId": "d-WA876T2Y1" } Success!
  8. resource "aws_ecs_service" "service" { name = "hoge" cluster = aws_ecs_cluster.cluster.id

    desired_count = 2 - launch_type = "FARGATE" platform_version = "1.4.0" enable_execute_command = true + capacity_provider_strategy { + capacity_provider = "FARGATE" + base = 1 + weight = 0 + } + + capacity_provider_strategy { + capacity_provider = "FARGATE_SPOT" + base = 0 + weight = 1 + } + ・・・略 } No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. terrafor plan •
  9. version: 0.0 Resources: - TargetService: Type: AWS::ECS::Service Properties: TaskDefinition: '<TASK_DEFINITION>'

    PlatformVersion: '1.4.0' LoadBalancerInfo: ContainerName: 'xxxxxx' ContainerPort: yyyy version: 0.0 Resources: - TargetService: Type: AWS::ECS::Service Properties: TaskDefinition: '<TASK_DEFINITION>' PlatformVersion: '14.0' LoadBalancerInfo: ContainerName: 'xxxxxx' ContainerPort: yyyy CapacityProviderStrategy: - Base: 1 CapacityProvider: 'FARGATE' Weight: 0 - Base: 0 CapacityProvider: 'FARGATE_SPOT' Weight: 1
  10. • • AWS Fargate Spot タスクで Spot 終了通知を処理するにはどうすればよいですか? • >

    Fargate Spot の中断によりタスクが停⽌した場合、stopCode は SpotInterruption として⾔ 及されることに注意してください。 • • •
  11. • • • 項⽬ 結果 Fargate Spotの稼働時間割合 99.992% 落ちた回数 106回

    MTBF(平均故障間隔) 約9⽇ MTTR(平均復旧時間) 1分
  12. Terraform will perform the following actions: # aws_ecs_service.service must be

    replaced -/+ resource "aws_ecs_service" "service" { 〜 略 ~ launch_type = "FARGATE" -> (known after apply) + capacity_provider_strategy { # forces replacement + base = 0 + capacity_provider = "FARGATE_SPOT" + weight = 1 } + capacity_provider_strategy { # forces replacement + base = 1 + capacity_provider = "FARGATE" + weight = 0 } 〜 略 } Plan: 1 to add, 0 to change, 1 to destroy. •
  13. • • resource "aws_ecs_service" "this" { ・・・略 lifecycle { ignore_changes

    = [ launch_type, capacity_provider_strategy ] } } • No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
  14. • Fargate Spotは使える場⾯があるなら積極的に使っていきたい • (作戦 ガンガンいこうぜ︕) • Fargate Spotのリスクを許容しづらいときは夜間などに絞って利⽤ できないか探る

    • (作戦 いのちをだいじに︕) • ECSサービスのデプロイメントコントローラによって Fargate Spotの適⽤⽅法が異なるので注意 • ECS / CODE_DEPLOY