k8s中的pod,-K8S中Pod优先级PriorityClass设置【CKA备考练习环境准备】5【2027新题】 - 44 resources: {}

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力2026 👁️ 124 次阅读

一同备考一同前进!!如有不当之处,欢迎指正!!

这次向广大备考CKA同学们分享Pod优先级PriorityClass题目的环境准备和参考解法,希望对备考CKA的同学们有帮助。

以下为往期的内容,有兴趣的同学欢迎参考。

K8S中Ingress-Nginx的部署与配置【CKA备考练习环境准备】1【2025新题】K8S中NetworkPolicy创建和验证【CKA备考练习环境准备】2【2025新题】K8S中StorageClass创建和验证【CKA备考练习环境准备】3【2025新题】K8S中Service创建和验证【CKA备考练习环境准备】4【2025新题】

一、k8s运行环境情况

1.1、详细环境情况信息如下:

root@k8s-ub-m01:~# kubectl version 拼多多帮助力入口

Client Version: v1.32.6

Kustomize Version: v5.5.0

Server Version: v1.32.0

root@k8s-ub-m01:~# kubeadm version -o short

v1.32.6

root@k8s-ub-m01:~# kubelet --version

Kubernetes v1.32.6

root@k8s-ub-m01:~# kubectl get no -owide

NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME

k8s-ub-m01 Ready control-plane 215d v1.32.6 192.168.148.121Ubuntu 22.04.5 LTS 5.15.0-164-generic containerd://1.7.27

k8s-ub-n01 Ready215d v1.32.6 192.168.148.122Ubuntu 22.04.5 LTS 5.15.0-164-generic containerd://1.7.27

k8s-ub-n02 Ready215d v1.32.6 192.168.148.123Ubuntu 22.04.5 LTS 5.15.0-164-generic containerd://1.7.27

root@k8s-ub-m01:~# kubectl get daemonset -n kube-system calico-node -owide

NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR

calico-node 3 3 3 3 3 kubernetes.io/os=linux 215d calico-node docker.io/calico/node:v3.29.1 k8s-app=calico-node

二、CKA练习环境Pod优先级PriorityClass题型预准备

2.1、CKA Pod优先级PriorityClass题型题干

Pod优先级PriorityClass

2.2、依据题目要求,准备相关的Pod优先级对象(PriorityClass)

创建用户定义的现有最高优先级值的PriorityClass优先级对象,可参考k8s官网的Example PriorityClass,其中的优先值是包含9个0,不要写错。

root@k8s-ub-m01:~# mkdir PriorityClassTest

root@k8s-ub-m01:~# cd PriorityClassTest

root@k8s-ub-m01:~/PriorityClassTest# vim max-user-priority.yaml

apiVersion: scheduling.k8s.io/v1

kind: PriorityClass

metadata:

name: max-user-priority

value: 1000000000

globalDefault: false

description: "max-user-priority."

root@k8s-ub-m01:~/PriorityClassTest# kubectl get pc

NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY

system-cluster-critical 2000000000 false 215d PreemptLowerPriority

system-node-critical 2000001000 false 215d PreemptLowerPriority

root@k8s-ub-m01:~/PriorityClassTest# kubectl apply -f max-user-priority.yaml

priorityclass.scheduling.k8s.io/max-user-priority created

root@k8s-ub-m01:~/PriorityClassTest# kubectl get pc

NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY

max-user-priority 1000000000 false 4s PreemptLowerPriority

system-cluster-critical 2000000000 false 215d PreemptLowerPriority

system-node-critical 2000001000 false 215d PreemptLowerPriority

2.3、依据题目要求,准备相关的命名空间和Deploy控制器

先创建priority的名称空间,再在名为priority的名称空间创建名为busybox-logger的Deploy root@k8s-ub-m01:~/PriorityClassTest# kubectl create ns priority

namespace/priority created

root@k8s-ub-m01:~/PriorityClassTest# kubectl -n priority create deploy busybox-logger --image=busybox -- sh -c 'echo "busybox pod ready now!" && sleep 3600'

deployment.apps/busybox-logger created

root@k8s-ub-m01:~/PriorityClassTest# kubectl -n priority get deploy

NAME READY UP-TO-DATE AVAILABLE AGE

busybox-logger 1/1 1 1 98s

三、CKA练习环境Pod优先级PriorityClass题型解答参考

3.1、根据Pod优先级PriorityClass考题题干,对相关已知资源进行确认

验证现有用户自定义的PriorityClass对象

root@k8s-ub-m01:~/PriorityClassTest# kubectl get pc

NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY

max-user-priority 1000000000 false 1m15s PreemptLowerPriority

system-cluster-critical 2000000000 false 215d PreemptLowerPriority

system-node-critical 2000001000 false 215d PreemptLowerPriority

3.2、创建题目所要求的PriorityClass对象

创建一个现有自定义PriorityClass对象的优先级数值小一的名称为high-priority的PriorityClass对象,可参考k8s官网的Example PriorityClass。修改前

root@k8s-ub-m01:~/PriorityClassTest# vim high-priority.yaml

apiVersion: scheduling.k8s.io/v1

kind: PriorityClass

metadata:

name: high-priority

value: 1000000

globalDefault: false

description: "This priority class should be used for XYZ service pods only."

修改后,(注:题目要求和已有的自定义PriorityClass对象的优先级数值小一,为9个9,数量不要弄错)

root@k8s-ub-m01:~/PriorityClassTest# vim high-priority.yaml

apiVersion: scheduling.k8s.io/v1

kind: PriorityClass

metadata:

name: high-priority

value: 999999999

globalDefault: false

description: "high-priority."

创建PriorityClass对象并进行确认

root@k8s-ub-m01:~/PriorityClassTest# kubectl apply -f high-priority.yaml

priorityclass.scheduling.k8s.io/high-priority created

root@k8s-ub-m01:~/PriorityClassTest# kubectl get pc

NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY

high-priority 999999999 false 14s PreemptLowerPriority

max-user-priority 1000000000 false 4m PreemptLowerPriority

system-cluster-critical 2000000000 false 215d PreemptLowerPriority

system-node-critical 2000001000 false 215d PreemptLowerPriority

3.3、按要求修改已存在的Deploy控制器参数

按照题目要求,使用kubectl edit命令在线修改在 priority namespace 中运行的现有 busybox-logger Deployment ,以使用high-priority 优先级类,即添加47行内容(特别注意缩进关系,不然会导致deploy下的Pod运行异常),设置Deploy控制器下Pod的优先级参数的写法可参考官网相关内容,即Pod priority。 root@k8s-ub-m01:~/PriorityClassTest# kubectl -n priority edit deploy busybox-logger

35 spec:

36 containers:

37 - command:

38 - sh

39 - -c

40 - echo "busybox pod ready now!" && sleep 3600

41 image: busybox

42 imagePullPolicy: Always

43 name: busybox

44 resources: {}

45 terminationMessagePath: /dev/termination-log

46 terminationMessagePolicy: File

47 priorityClassName: high-priority

48 dnsPolicy: ClusterFirst

deployment.apps/busybox-logger edited

3.4、确认修改后的运行状态

对所修改的Deploy及相应Pod的状态、参数进行确认 root@k8s-ub-m01:~/PriorityClassTest# kubectl -n priority get deploy

NAME READY UP-TO-DATE AVAILABLE AGE

busybox-logger 1/1 1 1 19m

root@k8s-ub-m01:~/PriorityClassTest# kubectl -n priority get pod busybox-logger-78bc88c999-nzh9d

NAME READY STATUS RESTARTS AGE

busybox-logger-78bc88c999-nzh9d 1/1 Running 0 3m49s

root@k8s-ub-m01:~/PriorityClassTest# kubectl -n priority describe pod busybox-logger-78bc88c999-nzh9d | grep priority

Namespace: priority

Priority Class Name: high-priority

Normal Scheduled 4m26s default-scheduler Successfully assigned priority/busybox-logger-78bc88c999-nzh9d to k8s-ub-n02

四、参考资料

无

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧