Customize Amazon EKS launch templates - AWS Batch

Customize Amazon EKS launch templates

AWS Batch on Amazon EKS supports launch templates. There are constraints on what your launch template can do.

Important

AWS Batch runs /etc/eks/bootstrap.sh. Don't run /etc/eks/bootstrap.sh in your launch template or cloud-init user-data scripts. You can add additional parameters besides the --kubelet-extra-args parameter to bootstrap.sh. To do this, set the AWS_BATCH_KUBELET_EXTRA_ARGS variable in the /etc/aws-batch/batch.config file. See the following example for details.

Note

If the launch template is changed after CreateComputeEnvironment is called, UpdateComputeEnvironment must be called to evaluate the version of the launch template for replacement.

Add kubelet extra arguments

AWS Batch supports adding extra arguments to the kubelet command. For the list of supported parameters, see kubelet in the Kubernetes documentation. In the following example, --node-labels mylabel=helloworld is added to the kubelet command line.

MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" --==MYBOUNDARY== Content-Type: text/x-shellscript; charset="us-ascii" #!/bin/bash mkdir -p /etc/aws-batch echo AWS_BATCH_KUBELET_EXTRA_ARGS=\"--node-labels mylabel=helloworld\" >> /etc/aws-batch/batch.config --==MYBOUNDARY==--

Configure the container runtime

You can use the AWS Batch CONTAINER_RUNTIME environment variable to configure the container runtime on a managed node. The following example sets the container runtime to containerd when bootstrap.sh runs. For more information, see containerd in the Kubernetes documentation.

Note

The CONTAINER_RUNTIME environment variable is equivalent to the --container-runtime option of bootstrap.sh. For more information, see Options in the Kubernetes documentation.

MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" --==MYBOUNDARY== Content-Type: text/x-shellscript; charset="us-ascii" #!/bin/bash mkdir -p /etc/aws-batch echo CONTAINER_RUNTIME=containerd >> /etc/aws-batch/batch.config --==MYBOUNDARY==--

Mount an Amazon EFS volume

You can use launch templates to mount volumes to the node. In the following example, the cloud-config packages and runcmd settings are used. For more information, see Cloud config examples in the cloud-init documentation.

MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" --==MYBOUNDARY== Content-Type: text/cloud-config; charset="us-ascii" packages: - amazon-efs-utils runcmd: - file_system_id_01=fs-abcdef123 - efs_directory=/mnt/efs - mkdir -p ${efs_directory} - echo "${file_system_id_01}:/ ${efs_directory} efs _netdev,noresvport,tls,iam 0 0" >> /etc/fstab - mount -t efs -o tls ${file_system_id_01}:/ ${efs_directory} --==MYBOUNDARY==--

To use this volume in the job, it must be added in the eksProperties parameter to RegisterJobDefinition. The following example is a large portion of the job definition.

{ "jobDefinitionName": "MyJobOnEks_EFS", "type": "container", "eksProperties": { "podProperties": { "containers": [ { "image": "public.ecr.aws/amazonlinux/amazonlinux:2", "command": ["ls", "-la", "/efs"], "resources": { "limits": { "cpu": "1", "memory": "1024Mi" } }, "volumeMounts": [ { "name": "efs-volume", "mountPath": "/efs" } ] } ], "volumes": [ { "name": "efs-volume", "hostPath": { "path": "/mnt/efs" } } ] } } }

In the node, the Amazon EFS volume is mounted in the /mnt/efs directory. In the container for the Amazon EKS job, the volume is mounted in the /efs directory.

IPv6 support

AWS Batch supports Amazon EKS clusters that have IPv6 addresses. No customizations are required for AWS Batch support. However, before you begin, we recommend that you review the considerations and conditions that are outlined in Assigning IPv6 addresses to pods and services in the Amazon EKS User Guide.