パパエンジニアのアウトプット帳

30歳に突入した1児のパパエンジニアのブログ

AWS Batch(AmazonLinux1)のボリュームサイズを増やす時はDockerのストレージ制限もお忘れなく

マネージド型コンピューティング環境(EC2)(AmazonLinux1)のAWS Batchのお話です。


AWS BatchでNo space left on deviceでエラーになった場合はディスク容量を増やせばとりあえずはいいのですが、EBSのサイズアップだけでなくDockerのストレージ制限もサイズアップしないとダメです。


下記2つのドキュメントをちゃんと読めば確かに今なら理解できるけど、当時はとりあえずEBSのサイズ増やせばいいんでしょ?って感じで斜め読みしてよく分かってなかった。。。

AWS Batch の「No space left on device」エラーを解決する

起動テンプレートを使用して、AWS Batch の Amazon EBS ボリュームのサイズを増やす


これでEBSのサイズ増やしてもNo space left on deviceになって??ってなっていたけど、下記の記事でようやく理解した。

https://bedford.io/projects/cli/doc/aws-batch.htmlDisk space for your jobsの項

By default, your Batch jobs will each have access to 10 GiB of scratch space. This is enough for most Nextstrain builds, but yours may require more.

Configuring more space requires a little bit of setup. It also helps to understand that Batch uses ECS to run containers on clusters of EC2 servers.

Each EC2 instance in an ECS cluster has a storage volume named /dev/xvdcz which is shared by all the containers/jobs running on that instance. The default size of this volume is 22 GiB, which comes from the AWS-managed ECS-optimized machine images (AMIs) used by Batch.

Each container/job is allowed to use up to 10 GiB of disk by default. This comes from Docker’s dm.basesize option.

In order to give your Batch jobs more disk, you have to increase both of these defaults. There are many approaches to doing this, but the simplest is to create a new EC2 launch template.

It’s quickest to create the launch template using the AWS Console, although you can also do it on the command-line.

First, add to the launch template an EBS storage volume with the device name /dev/xvdcz, volume size you want (e.g. 200 GiB), and a volume type of gp2. Make sure that the volume is marked for deletion on instance termination, or you’ll end up paying for old volumes indefinitely! This sets the size of the shared volume available to all containers on a single EC2 instance.

Next, under the “Advanced details” section, add a user data blob with the following text:


まとめると

  • ECSクラスター内の各EC2インスタンスには/dev/xvdczという名前のストレージボリュームがあり、そのインスタンス上で動作するすべてのコンテナ/ジョブで共有される
    • このボリュームのデフォルトサイズは22GiB
  • 各コンテナ/ジョブは、デフォルトでは最大10GiBのディスクを使用することができる
    • これはDockerのdm.basesizeオプションによるもの
  • もっと多くのディスクを割り当てたい場合はEBSとDockerストレージ制限の両方を増やす必要がある
    • そのシンプルな方法がEC2起動テンプレートを作ること


ちなみに/dev/xvdczAmazon Linux 1の場合でAmazon Linux 2だと/dev/xvda しかないようです。

起動テンプレートを使用して、AWS Batch の Amazon EBS ボリュームのサイズを増やす より

注: 起動テンプレートの DeviceName は、ご利用中の Amazon Elastic Container Service (Amazon ECS) に最適化された Amazon マシンイメージ (AMI) バージョンによって異なる場合があります。デフォルトでは、AWS Batch は Amazon Linux 1 に基づいており、2 つの Amazon EBS ボリューム (/dev/xvda および /dev/xvdcz) が付属しています。Amazon Linux 2 を使用している場合、AWS Batch には 1 つのボリューム (/dev/xvda) のみがあります。詳細については、AMI ストレージ設定をご参照ください。


Amazon Linux2の場合は/dev/xvdaのサイズを増やせばDockerも増えるみたいです。

dev.classmethod.jp


Amazon Linux2へのアップグレードもちゃんとやらないとな。。。