我想知道如何在不使用a的情况下默认为特定命名空间中的所有pod设置priorityClassglobalvalue: true
可能与准入 Controller 一起使用,但我不知道。
你有一个具体的例子吗?
最佳答案
PriorityClass : PriorityClass是非命名对象
PriorityClass还具有两个可选字段:globalDefault和description。
globalDefault字段指示此PriorityClass的值应用于不具有priorityClassName的Pod。
在系统中只能存在一个将globalDefault设置为true的PriorityClass。如果没有设置globalDefault的PriorityClass,则没有priorityClassName的Pod的优先级为零。
使用下面的yaml创建优先级类(未设置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
现在将优先级类添加到pod list ,并将它们安排在命名空间中$ 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
示例: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