美文网首页
k8s pod 优先级和抢占式调度

k8s pod 优先级和抢占式调度

作者: myonlyzzy | 来源:发表于2019-12-25 16:42 被阅读0次

简介

Pod priority and Preemption

在k8s里面调度节点的时候可以给pod指定Priority,让pod有不同的优先级.这样在scheduler调度pod的时候会优先调度优先级高的pod,如果发生资源不够的时候会触发抢占式调度.

启用 Pod priority and Preemption

  • 在1.11之后的版本中默认开启,并且在1.14中变成stable.
  • 在1.11之前的版本需要给kube-scheduler指定--feature-gates=PodPriority=true来开启

example

创建PriorityClass

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: high-priority
value: 1000000
globalDefault: false
description: "This priority class should be used for Test pods only."

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: low-priority
value: 10000
globalDefault: false
description: "This priority class should be used for Test pods only."

上面的yaml中定义了2个优先级 high-priority, low-priority.value分别是1000000,10000.

创建deployment

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deploy-high
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      hostNetwork: true
      priorityClassName: high-priority
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 8088

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deploy-low
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      hostNetwork: true
      priorityClassName: low-priority
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 8088


kubectl create -f ./nginx- deploy-low-priority.yaml
kubectl create -f ./nginx-deploy-high.yaml

About to try and schedule pod prometheus/nginx-deploy-high-76b56d5cc5-vpfjn
I1225 15:10:09.753527       1 scheduler.go:456] Attempting to schedule pod: prometheus/nginx-deploy-high-76b56d5cc5-vpfjn
I1225 15:10:09.753643       1 generic_scheduler.go:648] since alwaysCheckAllPredicates has not been set, the predicate evaluation is short circuited and there are chances of other predicates failing as well.
I1225 15:10:09.753696       1 factory.go:665] Unable to schedule prometheus/nginx-deploy-high-76b56d5cc5-vpfjn: no fit: 0/1 nodes are available: 1 node(s) didn't have free ports for the requested pod ports.; waiting
I1225 15:10:09.753741       1 factory.go:736] Updating pod condition for prometheus/nginx-deploy-high-76b56d5cc5-vpfjn to (PodScheduled==False, Reason=Unschedulable)
I1225 15:10:09.755568       1 generic_scheduler.go:318] Pod prometheus/nginx-deploy-high-76b56d5cc5-vpfjn is not eligible for more preemption.
I1225 15:10:09.755726       1 scheduling_queue.gkube
I1225 15:10:11.729743       1 generic_scheduler.go:1147] Node host108752172 is a potential node for preemption.
I1225 15:10:11.729916       1 generic_scheduler.go:648] since alwaysCheckAllPredicates has not been set, the predicate evaluation is short circuited and there are chances of other predicates failing as well.
I1225 15:10:11.730407       1 cache.go:309] Finished binding for pod ac27a286-4272-47a6-8677-735b23e981fa. Can be expired.
I1225 15:10:11.730627       1 scheduler.go:593] pod prometheus/nginx-deploy-high-76b56d5cc5-vpfjn is bound successfully on node host108752172, 1 nodes evaluated, 1 nodes were found feasible
I1225 15:10:12.066208       1 leaderelection.go:276] successfully renewed lease kube-system/kube-scheduler

分析

上面通过kubectl创建了2个deployment,nginx-deploy-low和nginx-deploy-high. nginx-deploy-low是先创建的,nginx-deploy-high后创建.上面的日志可以看到scheduler在调度nginx-deploy-high-76b56d5cc5-vpfjn的时候发现短裤8088已经被nginx-deploy-low的pod占了.然后nginx-deploy-high-76b56d5cc5-vpfjn这个pod因为Priority的值比low的pod高.所以scheduler会标记Node host108752172 is a potential node for preemption.为可抢占.然后正在running的nginx-deploy-low pod会变成为pending.nginx-deploy-high pod会变为running.

总结

  • 如果有2个pod在调度队列里面,一个的priority比较高,一个比较低.调度器会以优先调度priority值高的.这里因为实验环境不好重新.
  • 如果调度的时候发现资源不够了,scheduler会抢占优先级比较低的pod的资源优先给优先级高的pod.

相关文章

  • k8s pod 优先级和抢占式调度

    简介 Pod priority and Preemption 在k8s里面调度节点的时候可以给pod指定Prior...

  • Java中线程是抢占式的吗?

    Java的线程调度策略是“种基于优先级的抢占式调度”,Java这种抢占式凋度可能是分时的,即每个等待池中的轮流执行...

  • 多线程-3

    一.线程的调度:有两种方式1.时间片 2.抢占式: 高优先级的线程抢占CPU设置了优先级的话,优先级高的线程抢占到...

  • kubernetes scheduler抢占调度和优先级队列

    本文重点分析Kubernetes 1.10版本抢占式调度和优先级队列。在Kubernetes 1.8 以前,sch...

  • 进程调度算法1——FCFS、SJF、HNNR

    进程的调度方式有两种:非剥夺调度方式(非抢占式)和剥夺调度方式(抢占方式)。非抢占式:只允许进程主动放弃处理机。如...

  • UCOSIII_多任务创建(二)

    任务调度和切换就是让就绪表中优先级最高的任务获得CPU使用权,UCOSIII是抢占式的,高优先级任务可以抢了低优先...

  • 操作系统2.11

    更注重 “响应时间” 时间片大小为2 时间片大小为5 时间片太大 时间片太小 非抢占式的优先级调度算法 抢占式的优...

  • 深入理解K8S——Pod Preemption资源抢占

    深入理解K8S——Pod Preemption资源抢占 参考 Pod Priority and Preemptio...

  • 进程管理(三)进程调度

    (一) 调度器: 触发调度(轮转): ① 非抢占式调度:进程自己发起 ② 抢占式调度:操作系统内核引起。容易引起系...

  • 8. UCOS下优先级反转问题

    1. 写在前面: 1.1. ucos的进程调度是基于抢占式的,优先级较高的任务可以抢占系统的内核。 1.2. 只是...

网友评论

      本文标题:k8s pod 优先级和抢占式调度

      本文链接:https://www.haomeiwen.com/subject/ykgcoctx.html