简体   繁体   English

kubernetes 挂起吊舱优先级

[英]kubernetes pending pod priority

I have the following pods on my kubernetes (1.18.3) cluster:我的 kubernetes (1.18.3) 集群上有以下 pod:

NAME      READY   STATUS    RESTARTS   AGE
pod1      1/1     Running   0          14m
pod2      1/1     Running   0          14m
pod3      0/1     Pending   0          14m
pod4      0/1     Pending   0          14m

pod3 and pod4 cannot start because the node has capacity for 2 pods only. pod3 和 pod4 无法启动,因为该节点只能容纳 2 个 pod。 When pod1 finishes and quits, then the scheduler picks either pod3 or pod4 and starts it.当 pod1 完成并退出时,调度程序会选择 pod3 或 pod4 并启动它。 So far so good.到目前为止,一切都很好。

However, I also have a high priority pod (hpod) that I'd like to start before pod3 or pod4 when either of the running pods finishes and quits.但是,我也有一个高优先级的 pod (hpod),我想在 pod3 或 pod4 之前启动,当其中一个正在运行的 pod 完成并退出时。

So I created a priorityclass can be found in the kubernetes docs:所以我创建了一个优先级类,可以在 kubernetes 文档中找到:

kind: PriorityClass
metadata:
  name: high-priority-no-preemption
value: 1000000
preemptionPolicy: Never
globalDefault: false
description: "This priority class should be used for XYZ service pods only."

I've created the following pod yaml:我创建了以下 pod yaml:

apiVersion: v1
kind: Pod
metadata:
  name: hpod
  labels:
    app: hpod
spec:
  containers:
  - name: hpod
    image: ...
    resources:
      requests:
        cpu: "500m"
        memory: "500Mi"
      limits:
        cpu: "500m"
        memory: "500Mi"
  priorityClassName: high-priority-no-preemption

Now the problem is that when I start the high prio pod with kubectl apply -f hpod.yaml, then the scheduler terminates a running pod to allow the high priority pod to start despite I've set 'preemptionPolicy: Never'.现在的问题是,当我使用 kubectl apply -f hpod.yaml 启动高优先级 pod 时,调度程序会终止正在运行的 pod 以允许高优先级 pod 启动,尽管我已经设置了“preemptionPolicy:从不”。

The expected behaviour would be to postpone starting hpod until a currently running pod finishes.预期的行为是推迟启动 hpod 直到当前运行的 pod 完成。 And when it does, then let hpod start before pod3 or pod4.当它发生时,让 hpod 在 pod3 或 pod4 之前启动。

What am I doing wrong?我究竟做错了什么?

Prerequisites:先决条件:

This solution was tested on Kubernetes v1.18.3 , docker 19.03 and Ubuntu 18. Also text editor is required (ie sudo apt-get install vim ). This solution was tested on Kubernetes v1.18.3 , docker 19.03 and Ubuntu 18. Also text editor is required (ie sudo apt-get install vim ).

In Kubernetes documentation under How to disable preemption you can find Note :如何禁用抢占下的 Kubernetes 文档中,您可以找到注意

Note: In Kubernetes 1.15 and later, if the feature NonPreemptingPriority is enabled , PriorityClasses have the option to set preemptionPolicy: Never .注意:在 Kubernetes 1.15及更高版本中,如果启用了NonPreemptingPriority enabled ,则PriorityClasses可以选择设置preemptionPolicy: Never This will prevent pods of that PriorityClass from preempting other pods.这将防止该PriorityClass的 pod 抢占其他 pod。

Also under Non-preempting PriorityClass you have information:同样在Non-preempting PriorityClass下,您还有以下信息:

The use of the PreemptionPolicy field requires the NonPreemptingPriority feature gate to be enabled .使用 PreemptionPolicy 字段需要enabled NonPreemptingPriority特性门。

Later if you will check thoses Feature Gates info, you will find that NonPreemptingPriority is false , so as default it's disabled.稍后如果您检查那些Feature Gates信息,您会发现NonPreemptingPriorityfalse ,因此默认情况下它是禁用的。

Output with your current configuration: Output 与您当前的配置:

$ kubectl get pods
NAME             READY   STATUS    RESTARTS   AGE
nginx-normal     1/1     Running   0          32s
nginx-normal-2   1/1     Running   0          32s
$ kubectl apply -f prio.yaml
pod/nginx-priority created$ kubectl get pods
NAME             READY   STATUS    RESTARTS   AGE
nginx-normal-2   1/1     Running   0          48s
nginx-priority   1/1     Running   0          8s

To enable preemptionPolicy: Never you need to apply --feature-gates=NonPreemptingPriority=true to 3 files:要启用preemptionPolicy: Never不需要将--feature-gates=NonPreemptingPriority=true应用于 3 个文件:

/etc/kubernetes/manifests/kube-apiserver.yaml /etc/kubernetes/manifests/kube-apiserver.yaml

/etc/kubernetes/manifests/kube-controller-manager.yaml /etc/kubernetes/manifests/kube-controller-manager.yaml

/etc/kubernetes/manifests/kube-scheduler.yaml /etc/kubernetes/manifests/kube-scheduler.yaml

To check if this feature-gate is enabled you can check by using commands:要检查是否启用了此feature-gate ,您可以使用以下命令进行检查:

ps aux | grep apiserver | grep feature-gates
ps aux | grep scheduler | grep feature-gates
ps aux | grep controller-manager | grep feature-gates

For quite detailed information, why you have to edit thoses files please check this Github thread .有关非常详细的信息,为什么您必须编辑这些文件,请查看此 Github 线程

$ sudo su
# cd /etc/kubernetes/manifests/
# ls
etcd.yaml  kube-apiserver.yaml  kube-controller-manager.yaml  kube-scheduler.yaml

Use your text editor to add feature gate to those files使用您的文本编辑器将功能门添加到这些文件

# vi kube-apiserver.yaml

and add - --feature-gates=NonPreemptingPriority=true under spec.containers.command like in example bellow:并在spec.containers.command下添加- --feature-gates=NonPreemptingPriority=true ,如下例所示:

spec:
  containers:
  - command:
    - kube-apiserver
    - --feature-gates=NonPreemptingPriority=true
    - --advertise-address=10.154.0.31

And do the same with 2 other files.并对其他 2 个文件执行相同操作。 After that you can check if this flags were applied.之后,您可以检查是否应用了此标志。

$ ps aux | grep apiserver | grep feature-gates
root     26713 10.4  5.2 565416 402252 ?       Ssl  14:50   0:17 kube-apiserver --feature-gates=NonPreemptingPriority=true --advertise-address=10.154.0.31 

Now you have redeploy your PriorityClass .现在您已经重新部署了PriorityClass

$ kubectl get priorityclass
NAME                          VALUE        GLOBAL-DEFAULT   AGE
high-priority-no-preemption   1000000      false            12m
system-cluster-critical       2000000000   false            23m
system-node-critical          2000001000   false            23m
$ kubectl delete priorityclass high-priority-no-preemption
priorityclass.scheduling.k8s.io "high-priority-no-preemption" deleted
$ kubectl apply -f class.yaml 
priorityclass.scheduling.k8s.io/high-priority-no-preemption created

Last step is to deploy pod with this PriorityClass .最后一步是使用此PriorityClass部署 pod。

TEST测试

$ kubectl get po
NAME             READY   STATUS    RESTARTS   AGE
nginx-normal     1/1     Running   0          4m4s
nginx-normal-2   1/1     Running   0          18m
$ kubectl apply -f prio.yaml 
pod/nginx-priority created
$ kubectl get po
NAME             READY   STATUS    RESTARTS   AGE
nginx-normal     1/1     Running   0          5m17s
nginx-normal-2   1/1     Running   0          20m
nginx-priority   0/1     Pending   0          67s
$ kubectl delete po nginx-normal-2
pod "nginx-normal-2" deleted
$ kubectl get po
NAME             READY   STATUS    RESTARTS   AGE
nginx-normal     1/1     Running   0          5m55s
nginx-priority   1/1     Running   0          105s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM