OpenShift 4 - Pod 优先级

OpenShift 4.x HOL教程汇总
说明:本文已经在OpenShift 4.6环境中验证

优先级概念

一个 pod 的优先级表示这个 pod 相对于其他 pod 的重要性,OpenShift 会根据 Pod 的优先级确定分配运行资源的顺序。pod的优先级是其关联的PriorityClass对象定义的,在PriorityClass中用一个正整数指定优先级,数字越大,优先级越高。当 pod 被创建时会先被放入一个队列中等待调度。OpenShift会按照优先级从高到低的顺序为 pod分配运行资源。

  1. 如果node的资源充足,此时优先级高中低的 pod 都可运行。
  2. 如果node的资源不足以运行三个pod(且没有其它优先级低的pod),此时则OpenShift优先运行优先级高中的 pod,优先级低的 pod 需要等待可用的 node。
  3. 如果优先级中低的pod已经运行在node中,此时优先级高的pod等待运行,OpenShift会将优先级低的pod从节点驱逐走,然后在运行优先级高的pod。
    在这里插入图片描述

用PriorityClass定义优先级

系统缺省PriorityClass

在OpenShift中有2种缺省系统级别的PriorityClass。我们可以执行以下命令查看他们,他们的优先数值分别为2000000000和2000001000。

$ oc get priorityclasses
NAME                      VALUE        GLOBAL-DEFAULT   AGE
system-cluster-critical   2000000000   false            44d
system-node-critical      2000001000   false            44d

执行以下命令,可以看到sdn的pod使用的上面两种优先级非常高的系统PriorityClass,这样就能保证即便出现node资源非常紧张的情况,也会保障这些pod被优先运行。

$ oc get pods  -o custom-columns=NAME:.metadata.name,PRIORITY:.spec.priorityClassName -n openshift-sdn
NAME                   PRIORITY
ovs-48949              system-node-critical
ovs-5k4bj              system-node-critical
ovs-gsvhh              system-node-critical
ovs-h6td2              system-node-critical
ovs-zvjc9              system-node-critical
sdn-69hxq              system-node-critical
sdn-6pmth              system-node-critical
sdn-9gt4p              system-node-critical
sdn-controller-fzczj   system-cluster-critical
sdn-controller-sh9lp   system-cluster-critical
sdn-controller-zhngr   system-cluster-critical
sdn-k5n9b              system-node-critical
sdn-vp8zj              system-node-critical

自定义PriorityClass

如果不给pod指定优先级,则OpenShift会将它的优先级设为“None”,优先数值是最低的“0”。我们可以创建其他优先级PriorityClass,定制优先级的优先数值最大为10亿。
执行命令创建一个名为high-priority的PriorityClass。

$ oc create priorityclass high-priority --value=1000 --description="high priority"
$ oc get priorityclass high-priority
NAME            VALUE   GLOBAL-DEFAULT   AGE
high-priority   1000    false            33s

创建nginx.yaml文件,其中使用了上面定义的名为high-priority的PriorityClass。

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  priorityClassName: high-priority

执行以下命令,先创建pod,然后查看运行起来的pod,确认它使用了high-priority优先级。

$ oc get pods/nginx -o custom-columns=NAME:.metadata.name,PRIORITY:.spec.priorityClassName
NAME    PRIORITY
nginx   high-priority
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值