Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the old content of chinese website #10876

Closed
wants to merge 7 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
210 changes: 92 additions & 118 deletions content/zh/docs/tasks/manage-gpus/scheduling-gpus.md
Expand Up @@ -8,172 +8,146 @@ content_template: templates/task
{{% capture overview %}}


Kubernetes 提供对分布在节点上的 NVIDIA GPU 进行管理的**实验**支持。本页描述用户如何使用 GPU 以及当前使用的一些限制

{{% /capture %}}

{{% capture prerequisites %}}
Kubernetes 提供对分布在节点上的 AMD 和 NVIDIA GPU 进行管理的**实验**支持。对 NVIDIA GPU 的支持在 v1.6 中加入,已经经历了多次不向后兼容的迭代。而对 AMD GPU 的支持则在 v1.9 中通过 [device plugin](#deploying-amd-gpu-device-plugin) 加入。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原始的英文怎么移掉了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么意思?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来这篇中文本来就没有带英文,而且相当老。

附带英文的做法在一开始可行,但会造成需要维护两份英文文章,可以改为加链接的方式,review 的时候点过去看对应英文就好。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的基准是 master 分支,往 master 分支提交确实会有这个问题,不过现在不是以 master 分支为基准..所以不存在此总是。还是按规范走,方便 reviewer 的人比对原文。

由于注释格式是一致的,脱敏移除英文也是非常容易的,退一看,不移除注释,浏览器渲染也不会把注释原文展示出来。


这个页面介绍了用户如何在不同的 Kubernetes 版本中使用 GPU,以及当前存在的一些限制。

1. Kubernetes 节点必须预先安装好 NVIDIA 驱动,否则,Kubelet 将检测不到可用的GPU信息;如果节点的 Capacity 属性中没有出现 NIVIDA GPU 的数量,有可能是驱动没有安装或者安装失败,请尝试重新安装
{{% /capture %}}

2. 在整个 Kubernetes 系统中,feature-gates 里面特定的 **alpha** 特性参数 `Accelerators` 必须设置为 true:`--feature-gates="Accelerators=true"`
{{% capture body %}}

3. Kuberntes 节点必须使用 `docker` 引擎作为容器的运行引擎
## v1.8 往后
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

**从 1.8 版本往后,我们推荐通过 [device plugins](/docs/concepts/cluster-administration/device-plugins) 的方式来使用 GPU。**
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

上述预备工作完成后,节点会自动发现它上面的 NVIDIA GPU,并将其作为可调度资源暴露
在 1.10 版本之前,为了通过 device plugins 开启 GPU 的支持,我们需要在系统中将 `DevicePlugins`
这一 feature gate 显式的设置为 true:`--feature-gates="DevicePlugins=true"`。不过,从 1.10 版本开始,我们就不需要这一步骤了。
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

{{% /capture %}}
接着你需要在主机节点上安装对应厂商的 GPU 驱动 并运行对应厂商的 device plugin
([AMD](#deploying-amd-gpu-device-plugin), [NVIDIA](#deploying-nvidia-gpu-device-plugin))。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AMD](#%E9%83%A8%E7%BD%B2-amd-gpu-device-plugin), [NVIDIA](#%E9%83%A8%E7%BD%B2-nvidia-gpu-device-plugin)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the links does not work yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yeya24 I think it's the last one


{{% capture steps %}}
当上面的条件都满足,Kubernetes 将会暴露 `nvidia.com/gpu` 或
`amd.com/gpu` 来作为一种可调度的资源。

## API
你也能通过像请求 `cpu` 或 `memory` 一样请求 `<vendor>.com/gpu` 来在容器中使用 GPU。
然后,当你要通过指定资源请求来使用 GPU 时,存在着以下几点限制:
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

- GPU 仅仅支持在 `limits` 部分被指定,这表明:
* 你可以仅仅指定 GPU 的 `limits` 字段而不必须指定 `requests` 字段,因为 Kubernetes 会默认使用 limit 字段的值来作为 request 字段的默认值。
* 你能同时指定 GPU 的 `limits` 和 `requests` 字段,但这两个值必须相等。
* 你不能仅仅指定 GPU 的 `request` 字段而不指定 `limits`。
- 容器(以及 pods)并不会共享 GPU,也不存在对 GPU 的过量使用。
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
- 每一个容器能够请求一个或多个 GPU。然而只请求一个 GPU 的一部分是不允许的。

容器可以通过名称为 `alpha.kubernetes.io/nvidia-gpu` 的标识来申请需要使用的 NVIDIA GPU 的数量
下面是一个例子:

```yaml
apiVersion: v1
kind: Pod
kind: Pod
metadata:
name: gpu-pod
spec:
containers:
-
name: gpu-container-1
image: k8s.gcr.io/pause:2.0
resources:
limits:
alpha.kubernetes.io/nvidia-gpu: 2 # requesting 2 GPUs
-
name: gpu-container-2
image: k8s.gcr.io/pause:2.0
resources:
limits:
alpha.kubernetes.io/nvidia-gpu: 3 # requesting 3 GPUs
name: cuda-vector-add
spec:
restartPolicy: OnFailure
containers:
- name: cuda-vector-add
# https://github.com/kubernetes/kubernetes/blob/v1.7.11/test/images/nvidia-cuda/Dockerfile
image: "k8s.gcr.io/cuda-vector-add:v0.1"
resources:
limits:
nvidia.com/gpu: 1 # 请求一个GPU
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
```

### 部署 AMD GPU device plugin

- GPU 只能在容器资源的 `limits` 中配置

- 容器和 Pod 都不支持共享 GPU
[官方的 AMD GPU device plugin](https://github.com/RadeonOpenCompute/k8s-device-plugin) 有以下要求:

- 每个容器可以申请使用一个或者多个 GPU
- Kubernetes 节点必须预先安装 linux 上的 AMD GPU 驱动。
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

- GPU 必须以整数为单位被申请使用

- 所有节点的 GPU 硬件要求相同
要在你的集群已经启动的情况下部署 AMD device plugin,可以运行下面的命令来实现:
```
# 对于 Kubernetes v1.9
kubectl create -f https://raw.githubusercontent.com/RadeonOpenCompute/k8s-device-plugin/r1.9/k8s-ds-amdgpu-dp.yaml

# 对于 Kubernetes v1.10
kubectl create -f https://raw.githubusercontent.com/RadeonOpenCompute/k8s-device-plugin/r1.10/k8s-ds-amdgpu-dp.yaml
```
在这一页面来提交相关 device plugin 的 issues [RadeonOpenCompute/k8s-device-plugin](https://github.com/RadeonOpenCompute/k8s-device-plugin)。
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

如果在不同的节点上面安装了不同版本的 GPU,可以通过设置节点标签以及使用节点选择器的方式将 pod 调度到期望运行的节点上。工作流程如下:
### 部署 NVIDIA GPU device plugin

对于 NVIDIA,目前存在两种 device plugin 的实现:

在节点上,识别出 GPU 硬件类型,然后将其作为节点标签进行暴露
#### 官方的 NVIDIA GPU device plugin

```shell
NVIDIA_GPU_NAME=$(nvidia-smi --query-gpu=gpu_name --format=csv,noheader --id=0)
source /etc/default/kubelet
KUBELET_OPTS="$KUBELET_OPTS --node-labels='alpha.kubernetes.io/nvidia-gpu-name=$NVIDIA_GPU_NAME'"
echo "KUBELET_OPTS=$KUBELET_OPTS" > /etc/default/kubelet
```
[官方的 NVIDIA GPU device plugin](https://github.com/NVIDIA/k8s-device-plugin) 有以下要求:

- Kubernetes 的节点必须预先安装了 NVIDIA 驱动
- Kubernetes 的节点必须预先安装 [nvidia-docker 2.0](https://github.com/NVIDIA/nvidia-docker)
- 对于 docker 而不是 runc,nvidia-runtime 必须被设置为 [default-container-runtime](https://github.com/NVIDIA/k8s-device-plugin#preparing-your-gpu-nodes)
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
- NVIDIA 驱动版本 ~= 361.93

在 pod 上,通过节点[亲和性](/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity)规则为它指定可以使用的 GPU 类型
要在你的集群已经启动的情况下部署 NVIDIA device plugin,可以运行下面的命令来实现:
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

```yaml
kind: pod
apiVersion: v1
metadata:
annotations:
scheduler.alpha.kubernetes.io/affinity: >
{
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "alpha.kubernetes.io/nvidia-gpu-name",
"operator": "In",
"values": ["Tesla K80", "Tesla P100"]
}
]
}
]
}
}
}
spec:
containers:
-
name: gpu-container-1
resources:
limits:
alpha.kubernetes.io/nvidia-gpu: 2
```
# For Kubernetes v1.8
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.8/nvidia-device-plugin.yml

# For Kubernetes v1.9
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.9/nvidia-device-plugin.yml
```

上述设定可以确保 pod 会被调度到包含名称为 `alpha.kubernetes.io/nvidia-gpu-name` 的标签并且标签的值为 `Tesla K80` 或者 `Tesla P100` 的节点上
在这一页面来提交相关 device plugin 的 issues [NVIDIA/k8s-device-plugin](https://github.com/NVIDIA/k8s-device-plugin)。
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

#### GKE/GCE 中使用的 NVIDIA GPU device plugin

### 警告
[GKE/GCE 使用的 NVIDIA GPU device plugin](https://github.com/GoogleCloudPlatform/container-engine-accelerators/tree/master/cmd/nvidia_gpu)
并不要求使用 nvidia-docker,并且对于任何实现了 Kubernetes CRI 的容器运行时,都应该能够使用。这一实现已经在 [Container-Optimized OS](https://cloud.google.com/container-optimized-os/) 上进行了测试,并且在 1.9 版本之后会有对于 Ubuntu 的实验性代码。

在你 1.9 版本的集群上,你能使用下面的命令来安装 NVIDIA 驱动以及 device plugin:

当未来的 Kubernetes 版本能够更好的支持GPU以及一般的硬件加速器时,这里的 API 描述**将会随之做出变更**
```
# 在 Container-Optimized OS 上安装 NVIDIA 驱动:
kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/k8s-1.9/daemonset.yaml

# 在 Ubuntu 上安装 NVIDIA 驱动 (实验性质):
kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/k8s-1.9/nvidia-driver-installer/ubuntu/daemonset.yaml

## 访问 CUDA 库
# 安装 device plugin:
kubectl create -f https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.9/cluster/addons/device-plugins/nvidia-gpu/daemonset.yaml
```

在这一页面来提交相关 device plugin 的 issues 以及相应的安装方法 [GoogleCloudPlatform/container-engine-accelerators](https://github.com/GoogleCloudPlatform/container-engine-accelerators).

到目前为止,还需要预先在节点上安装 CUDA 库
## 集群内存在不同类型的 NVIDIA GPU

如果集群内部的不同节点上有不同类型的 NVIDIA GPU,那么你可以使用 [Node Label 和 NodeSelecter](/docs/tasks/configure-pod-container/assign-pods-nodes/) 来将pod调度到合适的节点上。
yeya24 marked this conversation as resolved.
Show resolved Hide resolved

为了避免后面使用库出现问题,可以将库放到 ``/var/lib/`` 下的某个文件夹下,或者直接改变库目录的权限(以后的版本会自动完成这一过程)
举一个例子:

```shell
# 为你的节点加上它们所拥有的 accelerator 类型的标签.
kubectl label nodes <node-with-k80> accelerator=nvidia-tesla-k80
kubectl label nodes <node-with-p100> accelerator=nvidia-tesla-p100
```

Pods能够通过 `hostPath` 卷来访问库
在 pod 的 spec 字段中指定 GPU 的类型:

```yaml
kind: Pod
apiVersion: v1
kind: Pod
metadata:
name: gpu-pod
name: cuda-vector-add
spec:
restartPolicy: OnFailure
containers:
- name: gpu-container-1
image: k8s.gcr.io/pause:2.0
resources:
limits:
alpha.kubernetes.io/nvidia-gpu: 1
volumeMounts:
- mountPath: /usr/local/nvidia/bin
name: bin
- mountPath: /usr/lib/nvidia
name: lib
volumes:
- hostPath:
path: /usr/lib/nvidia-375/bin
name: bin
- hostPath:
path: /usr/lib/nvidia-375
name: lib
- name: cuda-vector-add
# https://github.com/kubernetes/kubernetes/blob/v1.7.11/test/images/nvidia-cuda/Dockerfile
image: "k8s.gcr.io/cuda-vector-add:v0.1"
resources:
limits:
nvidia.com/gpu: 1
nodeSelector:
accelerator: nvidia-tesla-p100 # or nvidia-tesla-k80 etc.
```


## 未来


- Kubernetes 对硬件加速器的支持还处在早期阶段

- GPU 和其它的加速器很快会成为系统的本地计算资源

- 将引入更好的 API 以可扩展的方式提供和使用加速器

- Kubernets 将会自动确保应用在使用 GPU 时得到最佳性能

- 类似访问 CUDA 库这种关键的可用性问题将得到解决

{{% /capture %}}


这能够保证 pod 能够被调度到拥有你所指定类型的 GPU 的节点上去。