kuberntes - pod调度
2019-04-03 本文已影响20人
条子在洗澡
影响调度的因素
待调度Pod列表
可用node列表
调度算法 :主机过滤 | 主机打分
调度策略
主机过滤
#考虑的因素.....
NoDiskConflict
PodFitsResources
PodFitsPorts
MatchNodeSelector
HostName
NoVolumeZoneConflict
PodToleratesNodeTaints
CheckNodeMemoryPressure
CheckNodeDiskPressure
MaxEBSVolumeCount
MaxGCEPDVolumeCount
MaxAzureDiskVolumeCount
MatchInterPodAffinity
GeneralPredicates
NodeVolumeNodeConflict
........
主机打分
不同模式的打分规则
LeastRequestedPriority
公式
score=cpu ( ( capacity - sum ( requested ) ) * 10 / capacity) + memory
( ( capacity - sum ( requested) ) * 10 / capacity )/2
BalanceResourceAllocation
公式
score = 10 -abs ( cpuFraction - memoryFraction ) * 10
CalculateSpreadPriority 公式
Score = 10 * ((maxCount -counts)/ (maxCount))
手动指定
#给节点设置标签 name=vlue
kubectl get nodes --show-labels
kubectl label node k8s-node1 disktype=hdd
kubectl label node k8s-node2 disktype=ssd
#删除标签 name-
kubectl label node node2 disktype-
#使用标签查看nodes
[root@k8s-master1 k8s_yml]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master1 Ready master 3d v1.11.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-master1,node-role.kubernetes.io/master=
k8s-node1 Ready <none> 3d v1.11.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=hdd,kubernetes.io/hostname=k8s-node1
k8s-node2 Ready <none> 3d v1.11.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/hostname=k8s-node2
[root@k8s-master1 k8s_yml]# kubectl get nodes --show-labels --selector=disktype=ssd
NAME STATUS ROLES AGE VERSION LABELS
k8s-node2 Ready <none> 3d v1.11.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/hostname=k8s-node2
#定义pod的yaml (nodeSelector 参数)
vim nginx_pod_nodeselector.yaml
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
app: web2
spec:
nodeSelector:
disktype: ssd
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
#创建pod
[root@k8s-master1 k8s_yml]# kubectl apply -f nginx_pod_nodeselector.yaml
pod/static-web created
#查看pod信息,很明显在指定的k8s-node2上创建
[root@k8s-master1 k8s_yml]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
static-web 1/1 Running 0 26s 10.244.2.23 k8s-node2
由于维护需要关停某个节点
#cordon 新创建的pod不会被调度到此node上已经调度上去的pod还在运行,需要删除pod让其重新在其他节点生成
#开始维护
kubectl cordon k8s-node1
#创建10个pod
kubectl run nginx --image=nginx --replicas=10
#解除维护
kubectl uncordon k8s-node1
#将nginx容器增加到20个
kubectl scale --replicas=20 deployment/nginx
#查看容器信息
kubectl get pods -o wide
#删除容器
kubectl delete deployments. nginx
#drain 标记后 此节点不再被调度pod,且此节点上已经运行的pod会被驱逐(evicted)到其他节点
#创建5个pod
kubectl run nginx --image=nginx --replicas=5
#查看容器信息
[root@k8s-master1 k8s_yml]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-64f497f8fd-2mn8h 1/1 Running 0 7s 10.244.1.23 k8s-node1
nginx-64f497f8fd-5gp5h 1/1 Running 0 7s 10.244.2.35 k8s-node2
nginx-64f497f8fd-6p6hf 1/1 Running 0 7s 10.244.1.25 k8s-node2
nginx-64f497f8fd-847nd 1/1 Running 0 7s 10.244.1.24 k8s-node1
nginx-64f497f8fd-dqdnr 1/1 Running 0 7s 10.244.2.34 k8s-node2
#开始维护
kubectl drain k8s-node1 --ignore-daemonsets
#查看容器信息
[root@k8s-master1 k8s_yml]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-64f497f8fd-2png4 1/1 Running 0 16s 10.244.2.37 k8s-node2
nginx-64f497f8fd-5gp5h 1/1 Running 0 33s 10.244.2.35 k8s-node2
nginx-64f497f8fd-dqdnr 1/1 Running 0 33s 10.244.2.34 k8s-node2
nginx-64f497f8fd-nbv77 1/1 Running 0 16s 10.244.2.39 k8s-node2
nginx-64f497f8fd-wghff 1/1 Running 0 16s 10.244.2.38 k8s-node2
#解除维护
kubectl uncordon k8s-node1
#查看容器信息
kubectl get pods -o wide
#taint 只有标签为keyxx=valuexx的pod才能调度到此node,否则不能
#查看taint
kubectl describe nodes k8s-node1 | grep -A1 Tain
#设置taint
kubectl taint nodes k8s-node1 keyxx=valuexx:NoSchedule
#解除taint
kubectl taint nodes k8s-node1 keyxx:NoSchedule-
vim nginx_pod_taint.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
restartPolicy: OnFailure
tolerations:
- key: "keyxx"
operator: "Equal"
value: "valuexx"
effect: "NoSchedule"
containers:
- name: myapp-container
image: nginx