资源requests如何影响调度
调度器如何判断Pod调度到某个节点上
- 通过设置资源requests,可以设置Pod的最小资源分配请求,调度器在调度时只考虑那些未分配资源量满足Pod需求量的节点
- 调度器在调度时并不关心各类资源在当前的实际使用量,而是关注节点上部署所有Pod的资源requests的总和,当一个节点的request > capacity那么调度器将不予Pod分配该节点,否则会启动失败
调度器在调度时如何选择最佳节点
- 二个函数LeastRequestedPriority & MostRequestedPriority
- LeastRequestedPriority 优先将Pod调度到requests相对较少的节点上
- MostRequestedPriority 优质将Pod调度到requests相对较多的节点上
- 但是调度器在调度时只有选择一种函数,那么在什么情况下会使用MostRequestedPriority函数呢,在云计算环境背景下,计算实例是按节点计费的,通过让Pod紧凑型编排,这时就可以使用MostRequestedPriority函数以节省费用的开销
如果查看节点的资源使用状态
- 在Kubernetes集群中调度器apiserver需要知道每个集群节点的资源使用情况,比如有多少CPU & MEM并且已被分配了多少量,在Kubernetes每个节点上都安装一个kubelet的组件,Kubelet会定时向API-server发送节点的资源状态数据,并通过节点资源对外访问(schedule controller通信)
- 查看节点的资源使用情况,如下命令
1 <root@HK-K8S-CP ~># kubectl describe nodes hk-k8s-wn1
2 Name: hk-k8s-wn1
3 Roles: worker
4 Labels: beta.kubernetes.io/arch=amd64
5 beta.kubernetes.io/os=linux
6 kubernetes.io/arch=amd64
7 kubernetes.io/hostname=hk-k8s-wn1
8 kubernetes.io/ingress=pre
9 kubernetes.io/os=linux
10 node-role.kubernetes.io/worker=
11 topology.diskplugin.csi.alibabacloud.com/zone=cn-hongkong-c
12 Annotations: csi.volume.kubernetes.io/nodeid: {"diskplugin.csi.alibabacloud.com":"i-j6cg230darhjdqdf9n75"}
13 io.cilium.network.ipv4-cilium-host: 172.20.0.105
14 io.cilium.network.ipv4-health-ip: 172.20.0.102
15 io.cilium.network.ipv4-pod-cidr: 172.20.0.64/26
16 kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
17 node.alpha.kubernetes.io/ttl: 0
18 volumes.kubernetes.io/controller-managed-attach-detach: true
19 CreationTimestamp: Tue, 16 Mar 2021 14:04:25 +0800
20 Taints: <none>
21 Unschedulable: false
22 Lease:
23 HolderIdentity: hk-k8s-wn1
24 AcquireTime: <unset>
25 RenewTime: Fri, 13 Aug 2021 15:29:41 +0800
26 Conditions:
27 Type Status LastHeartbeatTime LastTransitionTime Reason Message
28 ---- ------ ----------------- ------------------ ------ -------
29 NetworkUnavailable False Tue, 16 Mar 2021 23:44:59 +0800 Tue, 16 Mar 2021 23:44:59 +0800 CiliumIsUp Cilium is running on this node
30 MemoryPressure False Fri, 13 Aug 2021 15:28:39 +0800 Tue, 16 Mar 2021 14:04:25 +0800 KubeletHasSufficientMemory kubelet has sufficient memory available
31 DiskPressure False Fri, 13 Aug 2021 15:28:39 +0800 Tue, 16 Mar 2021 14:04:25 +0800 KubeletHasNoDiskPressure kubelet has no disk pressure
32 PIDPressure False Fri, 13 Aug 2021 15:28:39 +0800 Tue, 16 Mar 2021 14:04:25 +0800 KubeletHasSufficientPID kubelet has sufficient PID available
33 Ready True Fri, 13 Aug 2021 15:28:39 +0800 Tue, 16 Mar 2021 23:44:57 +0800 KubeletReady kubelet is posting ready status
34 Addresses:
35 InternalIP: 172.19.1.120
36 Hostname: hk-k8s-wn1
37 Capacity:
38 cpu: 2
39 ephemeral-storage: 41152812Ki
40 hugepages-1Gi: 0
41 hugepages-2Mi: 0
42 memory: 3883608Ki
43 pods: 110
44 Allocatable:
45 cpu: 2
46 ephemeral-storage: 37926431477
47 hugepages-1Gi: 0
48 hugepages-2Mi: 0
49 memory: 3781208Ki
50 pods: 110
51 System Info:
52 Machine ID: 20191225111607875619293640639763
53 System UUID: dcbce1f0-bd51-4124-b199-a0d81cf89874
54 Boot ID: b0ee5748-9383-46a9-91cb-a984f869ed40
55 Kernel Version: 5.11.1-1.el7.elrepo.x86_64
56 OS Image: CentOS Linux 7 (Core)
57 Operating System: linux
58 Architecture: amd64
59 Container Runtime Version: docker://19.3.12
60 Kubelet Version: v1.18.5
61 Kube-Proxy Version: v1.18.5
62 PodCIDR: 172.20.1.0/24
63 PodCIDRs: 172.20.1.0/24
64 Non-terminated Pods: (10 in total)
65 Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE
66 --------- ---- ------------ ---------- --------------- ------------- ---
67 default prometheus-kube-state-metrics-858f88ff6-gb2lh 0 (0%) 0 (0%) 0 (0%) 0 (0%) 56d
68 default prometheus-node-exporter-cq6fp 0 (0%) 0 (0%) 0 (0%) 0 (0%) 56d
69 default rabbitmq-1 1 (50%) 1 (50%) 2Gi (55%) 2Gi (55%) 56d
70 default zk-1 100m (5%) 0 (0%) 128M (3%) 0 (0%) 77d
71 kube-system cilium-operator-789c9b45c9-fvjkx 0 (0%) 0 (0%) 0 (0%) 0 (0%) 149d
72 kube-system cilium-wcrm7 100m (5%) 0 (0%) 100Mi (2%) 0 (0%) 149d
73 kube-system csi-plugin-tsjwb 100m (5%) 500m (25%) 128Mi (3%) 1Gi (27%) 88d
74 kube-system hubble-relay-7995686985-bhp4k 0 (0%) 0 (0%) 0 (0%) 0 (0%) 146d
75 kube-system hubble-ui-769fb95577-kqn7m 0 (0%) 0 (0%) 0 (0%) 0 (0%) 146d
76 kube-system kube-router-njnhh 250m (12%) 0 (0%) 250Mi (6%) 0 (0%) 149d
77 Allocated resources:
78 (Total limits may be over 100 percent, i.e., overcommitted.)
79 Resource Requests Limits
80 -------- -------- ------
81 cpu 1550m (77%) 1500m (75%)
82 memory 2711624Ki (71%) 3Gi (83%)
83 ephemeral-storage 0 (0%) 0 (0%)
84 hugepages-1Gi 0 (0%) 0 (0%)
85 hugepages-2Mi 0 (0%) 0 (0%)
86 Events: <none>