HAOJX

在kubernetes中如何增加和使用node节点上的自定义资源数量

字数统计: 160阅读时长: 1 min
2018/12/03 Share

在node节点上 , 节点上各个类型资源可用量 , 体现在node对象的status字段中

1
2
3
4
5
6
7
8
9
10
apiVersion: v1
kind: Node
metadata:
name: node-1
...
Status:
Capacity:
cpu: 2
memory: 2049008Ki
.....

那么如何增加一个自定义类型资源的数量呢

增加方法

1
2
3
4
5
6
7
8
#启动一个代理
kubectl proxy

#执行pacth操作
curl --header "Content-Type: application/json-patch+json" \
--request PATCH \
--data '[{"op": "add", "path":"/status/capacity/nvidia.com/gpu", "value": "1"}]' \
http://localhost:8001/api/v1/nodes/<YOUR-NODE-NAME>/status

使用方法

在pod中声明

1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: v1
kind: Pod
metadata:
name: cuda-vector-add
spec:
restartPolicy: OnFailure
containers:
- name: cuda-vector-add
image: "k8s.gcr.io/cuda-vector-add:v0.1"
resources:
limits:
nvidia.com/gpu: 1

在字段spec.containers.resources.limits 下增加即可

CATALOG
  1. 1. 增加方法
  2. 2. 使用方法