本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
在 EKS 资源上创建基于 GPU 的任务
本节介绍如何在上运行亚马逊 EKS GPU 工作负载Amazon Batch。
在亚马逊 EKS 上创建基于 GPU 的Kubernetes集群
在 Amazon EKS 上创建基于 GPU 的Kubernetes集群之前,必须完成中的步骤。亚马逊 EKS Amazon Batch 上入门此外,还要考虑以下几点:
-
Amazon Batch支持使用 NVIDIA GPU 的实例类型。
-
默认情况下,Amazon Batch选择版本与您的亚马逊 EKS 集群控制平面Kubernetes版本相匹配的 Amazon EKS 加速 AMI。
$
cat <<EOF > ./batch-eks-gpu-ce.json { "computeEnvironmentName": "My-Eks-GPU-CE1", "type": "MANAGED", "state": "ENABLED", "eksConfiguration": { "eksClusterArn": "arn:aws:eks:
<region>
:<account>
:cluster/<cluster-name>
", "kubernetesNamespace": "my-aws-batch-namespace" }, "computeResources": { "type": "EC2", "allocationStrategy": "BEST_FIT_PROGRESSIVE", "minvCpus": 0, "maxvCpus": 1024, "instanceTypes": [ "p3dn.24xlarge", "p4d.24xlarge" ], "subnets": [ "<eks-cluster-subnets-with-access-to-internet-for-image-pull>
" ], "securityGroupIds": [ "<eks-cluster-sg>
" ], "instanceRole": "<eks-instance-profile>
" } } EOF$
aws batch create-compute-environment --cli-input-json file://./batch-eks-gpu-ce.json
Amazon Batch不代表你管理 NVIDIA GPU 设备插件。您必须将此插件安装到您的 Amazon EKS 集群中,并允许它以Amazon Batch节点为目标。有关更多信息,请参阅中的Kubernetes启用 GPU 支持
要将NVIDIA设备插件 (DaemonSet
) 配置为以Amazon Batch节点为目标,请运行以下命令。
# pull nvidia daemonset spec
$
curl -O https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v0.12.2/nvidia-device-plugin.yml
# using your favorite editor, add Batch node toleration # this will allow the DaemonSet to run on Batch nodes - key: "batch.amazonaws.com/batch-node" operator: "Exists"
$
kubectl apply -f nvidia-device-plugin.yml
我们不建议您在计算环境和作业队列的相同配对中将基于计算(CPU 和内存)的工作负载与基于 GPU 的工作负载混合。这是因为计算任务可能会耗尽 GPU 容量。
要连接作业队列,请运行以下命令。
$
cat <<EOF > ./batch-eks-gpu-jq.json { "jobQueueName": "My-Eks-GPU-JQ1", "priority": 10, "computeEnvironmentOrder": [ { "order": 1, "computeEnvironment": "My-Eks-GPU-CE1" } ] } EOF
$
aws batch create-job-queue --cli-input-json file://./batch-eks-gpu-jq.json
创建亚马逊 EKS GPU 任务定义
nvidia.com/gpu
目前仅支持且您设置的资源值必须为整数。你不能使用 GPU 的几部分。有关更多信息,请参阅Kubernetes文档中的调度 GPU
要为 Amazon EKS 注册 GPU 任务定义,请运行以下命令。
$
cat <<EOF > ./batch-eks-gpu-jd.json { "jobDefinitionName": "MyGPUJobOnEks_Smi", "type": "container", "eksProperties": { "podProperties": { "hostNetwork": true, "containers": [ { "image": "nvcr.io/nvidia/cuda:10.2-runtime-centos7", "command": ["nvidia-smi"], "resources": { "limits": { "cpu": "1", "memory": "1024Mi", "nvidia.com/gpu": "1" } } } ] } } } EOF
$
aws batch register-job-definition --cli-input-json file://./batch-eks-gpu-jd.json
在您的亚马逊 EKS 集群中运行 GPU 任务
GPU 资源是不可压缩的。 Amazon Batch为 GPU 任务创建 pod 规范,其中请求值等于限制值。这是一项Kubernetes要求。
要提交 GPU 作业,请运行以下命令。
$
aws batch submit-job --job-queue My-Eks-GPU-JQ1 --job-definition MyGPUJobOnEks_Smi --job-name My-Eks-GPU-Job
# locate information that can help debug or find logs (if using Amazon CloudWatch Logs with Fluent Bit)
$
aws batch describe-jobs --job
<job-id>
| jq '.jobs[].eksProperties.podProperties | {podName, nodeName}'{ "podName": "aws-batch.f3d697c4-3bb5-3955-aa6c-977fcf1cb0ca", "nodeName": "ip-192-168-59-101.ec2.internal" }