[英]set priorityclass by default for a namespace
I would like to know how it's possible to set a priorityClass by default for all pods in a specific namespace without using a globalvalue: true
我想知道如何在不使用全局值的情况下为特定命名空间中的所有 Pod 默认设置 priorityClass
globalvalue: true
may be with admission controller but i don't know.可能会入场 controller 但我不知道。
Do you have an concret example for that?你有一个具体的例子吗?
PriorityClass : A PriorityClass is a non-namespaced object PriorityClass : PriorityClass 是非命名空间的 object
PriorityClass also has two optional fields: globalDefault and description. PriorityClass 还有两个可选字段:globalDefault 和 description。
The globalDefault field indicates that the value of this PriorityClass should be used for Pods without a priorityClassName. globalDefault 字段表示此 PriorityClass 的值应该用于没有 priorityClassName 的 Pod。
Only one PriorityClass with globalDefault set to true can exist in the system .系统中只能存在一个 globalDefault 设置为 true 的 PriorityClass 。 If there is no PriorityClass with globalDefault set, the priority of Pods with no priorityClassName is zero.
如果没有设置 globalDefault 的 PriorityClass,则没有 priorityClassName 的 Pod 的优先级为零。
Create Priority Class as using below yaml (no globalDefault flag is set)使用以下 yaml 创建优先级 Class(未设置 globalDefault 标志)
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000000
description: "This priority class should be used for pods."
$ kubectl get priorityclasses.scheduling.k8s.io
NAME VALUE GLOBAL-DEFAULT AGE
high-priority 1000000 false 10s
Now add priority class to pod manifest and schedule them in your namespace现在将优先级 class 添加到 pod 清单并将它们安排在您的命名空间中
$ kubectl create namespace priority-test
namespace/priority-test created
$ kubectl get namespaces
NAME STATUS AGE
default Active 43m
kube-node-lease Active 43m
kube-public Active 43m
kube-system Active 43m
priority-test Active 5s
Example: pod.yaml示例:pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
priorityClassName: high-priority
$ kubectl apply -f pod.yaml -n priority-test
pod/nginx created
ubuntu@k8s-master-1:~$ kubectl get all -n priority-test
NAME READY STATUS RESTARTS AGE
pod/nginx 1/1 Running 0 25s
$ kubectl describe pod -n priority-test nginx | grep -i priority
Namespace: priority-test
Priority: 1000000
Priority Class Name: high-priority
Normal Scheduled <unknown> default-scheduler Successfully assigned priority-test/nginx to worker-1
Currently per namespace priorities are not possible.目前每个命名空间的优先级是不可能的。
But you can achieve similar result if instead you set default priorityClass
with globalDefault: true
and eg value: 1000
.但是,如果您将默认
priorityClass
设置为globalDefault: true
和例如value: 1000
,则可以获得类似的结果。 Next create another lower priority class and with eg value: 100
and add it to all dev/staging pods.接下来创建另一个较低优先级的 class 并使用例如
value: 100
并将其添加到所有 dev/staging pod。
Btw.顺便提一句。 not directly related to the question but it would be much easier to accomplish what you need if you use
nodeSelector
s and schedule dev pods to separate nodes.与问题没有直接关系,但如果您使用
nodeSelector
并将开发 pod 安排到单独的节点,那么完成您需要的工作会容易得多。 This way production pods don't have to compete for resources with non-essential pods.这样,生产 pod 就不必与非必要的 pod 竞争资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.