问题描述
在 Kubernetes 中如何通过设置 Pod 优先级实现抢占功能。
问题分析
在 Kubernetes中提供了 PriorityClass 类型的资源对象,通过创建 PriorityClass 可以实现 Pod 的优先级。
问题解决
1.创建 PriorityClass
$ cat priorityclass-test.yaml
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority-nonpreempting
value: 1000000
preemptionPolicy: Never
globalDefault: false
description: "This priority class will not cause other pods to be preempted."
$ kubectl apply -f priorityclass-test.yaml
$ kubectl get priorityclasses|grep high-priority
high-priority-nonpreempting 1000000 false 33s
2.使用PriorityClass 创建 Pod
$ cat priorityclass-pod-test.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
priorityClassName: high-priority-nonpreempting
$ kubectl apply -f priorityclass-pod-test.yaml
$ kubectl get pod -n default
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 17m
参考链接
[1] https://kubernetes.io/zh/docs/concepts/scheduling-eviction/pod-priority-preemption/ 如果您有其他问题,欢迎您联系火山引擎技术支持服务