LoginSignup
0
0

自分メモ ECS起動タスク数の設定で詰まったこと

Last updated at Posted at 2024-02-08

CDK(L3)で以下のようなECS起動設定を行っていたが必要タスク数が想定通りにならなかった。

const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, properties.fargateServiceId, {
      cluster,
      assignPublicIp: true,
      serviceName: properties.fargateServiceId,
      memoryLimitMiB: properties.fargateMem,
      desiredCount: properties.fargateDesiredCount, ← ここを4で設定
      cpu: properties.fargateCpu,
      taskImageOptions: {
        image: containerImage,
        logDriver:ecs.LogDrivers.firelens({})
      },
      loadBalancer: alb,
      platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
      enableExecuteCommand: true,
    });

desiredCountを任意の数に設定することで必要タスク数を調整できると思っていたが、
実際に起動すると1タスクしか起動しない形だった。

前試したときはここだけで問題なかったのに…と困っていたがどうやら
AutoScalingPolicyの設定追加の影響によるものだとわかった。

const autoscaling = loadBalancedFargateService.service.autoScaleTaskCount({ maxCapacity: 5 });
    autoscaling.scaleOnMemoryUtilization('ScalingOnMemory', {
      targetUtilizationPercent: 80,
      scaleInCooldown: Duration.seconds(60),
      scaleOutCooldown: Duration.seconds(60)
    }

上記がオートスケール設定だがmaxCapacityを5で設定しているがminCapacityの設定はない状態。
この場合minCapacityはデフォルト値の1で設定される。

このminCapacity値がdisiredCountより優先されるようで、必要数(常時起動数)が1になっていた。
なのでminCapacity: 4を追加する形で対処した。

詰まったのでメモがてら記事化

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0