许吉友 - 运维

为节点创建扩展资源。

$ kubectl proxy &
$ curl --header "Content-Type: application/json-patch+json" \
--request PATCH \
--data '[{"op": "add", "path": "/status/capacity/example.com~1dongle", "value": "4"}]' \
http://localhost:8001/api/v1/nodes/<your-node-name>/status
$ kubectl describe node <your-node-name>

当创建 POD 时,会自动调度到有指定资源的节点上!!!

这里还需要注意的是,资源必须是整数!!!


为容器分派扩展资源

extended-resource-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: extended-resource-demo
spec:
  containers:
  - name: extended-resource-demo-ctr
    image: nginx
    resources:
      requests:
        example.com/dongle: 3
      limits:
        example.com/dongle: 3
$ kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod.yaml
$ kubectl get pod extended-resource-demo
$ kubectl describe pod extended-resource-demo

extended-resource-pod-2.yaml

apiVersion: v1
kind: Pod
metadata:
  name: extended-resource-demo-2
spec:
  containers:
  - name: extended-resource-demo-2-ctr
    image: nginx
    resources:
      requests:
        example.com/dongle: 2
      limits:
        example.com/dongle: 2
$ kubectl apply -f https://k8s.io/examples/pods/resource/extended-resource-pod-2.yaml
$ kubectl describe pod extended-resource-demo-2
Events:
  Type     Reason            Age        From               Message
  ----     ------            ----       ----               -------
  Warning  FailedScheduling  <unknown>  default-scheduler  0/6 nodes are available: 6 Insufficient example.com/dongle
$ kubectl get pod extended-resource-demo-2
NAME                       READY   STATUS    RESTARTS   AGE
extended-resource-demo-2   0/1     Pending   0          5m21s

第二个 Pod 创建不成功.