

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建一个 GPU-based Kubernetes 亚马逊 EKS 上的集群
<a name="create-gpu-cluster-eks"></a>

在 Amazon EKS 上创建 GPU-based Kubernetes集群之前，必须完成中的步骤[亚马逊 EK AWS Batch S 入门](getting-started-eks.md)。此外，请考虑以下操作：
+ AWS Batch 支持 NVIDIA GPU 的实例类型。
+ 默认情况下， AWS Batch 选择亚马逊 EKS 加速 AMI，其Kubernetes版本与您的亚马逊 EKS 集群控制平面版本相匹配。

```
$ 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
```

AWS Batch 不代表你管理 NVIDIA GPU 设备插件。您必须将此插件安装到您的 Amazon EKS 集群中，并允许它以 AWS Batch 节点为目标。有关更多信息，请参阅中的[Kubernetes](https://github.com/NVIDIA/k8s-device-plugin#enabling-gpu-support-in-kubernetes)启用 GPU 支持 GitHub。

要将NVIDIA设备插件 (`DaemonSet`) 配置为目标 AWS 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-based 工作负载混合使用。这是因为计算作业可能会耗尽 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
```