Mock exam 3 : question 4: setting priority class in pod

Hi Team,

Kindly assist with the error message reported in the question below. Thanks !

Question:

Create a PriorityClass named low-priority with a value of 50000. A pod named lp-pod exists in the namespace low-priority. Modify the pod to use the priority class you created. Recreate the pod if necessary.

Is the PriorityClass low-priority created?

Low priority class value is set properly to 50000

Pod lp-pod uses the low-priority PriorityClass

Answer:

ontrolplane ~ ➜  cat pc.yaml 
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: low-priority
value: 50000
globalDefault: false
description: "This priority classis low priority class."

controlplane ~ ➜  k apply -f pc.yaml 
priorityclass.scheduling.k8s.io/low-priority created

controlplane ~ ➜  k get pc 
NAME                      VALUE        GLOBAL-DEFAULT   AGE   PREEMPTIONPOLICY
low-priority              50000        false            5s    PreemptLowerPriority
system-cluster-critical   2000000000   false            13m   PreemptLowerPriority
system-node-critical      2000001000   false            13m   PreemptLowerPriority

controlplane ~ ✖ k get pod lp-pod  -o yaml -n low-priority | grep -i "priorityClassName"  <=Report Nothing 

controlplane ~ ✖ k get pod lp-pod  -o yaml -n low-priority > test.yaml 

controlplane ~ ➜  vim test.yaml 

controlplane ~ ➜  cat test.yaml | grep -i "priorityClassName"
  priorityClassName: low-priority

controlplane ~ ✖ k replace --force -f test.yaml 
pod "lp-pod" deleted
Error from server (Forbidden): pods "lp-pod" is forbidden: the integer value of priority (0) must not be provided in pod spec; priority admission controller computed 50000 from the given PriorityClass name
controlplane ~ ➜  k get pods -n low-priority
No resources found in low-priority namespace.
  • Contents of test.yaml below:
apiVersion: v1
kind: Pod
metadata:
  annotations:
    cni.projectcalico.org/containerID: 556d9f20545f8e2c26158a01cdc0bbfc771b916ef2ae7872780403a51e453b8e
    cni.projectcalico.org/podIP: 172.17.1.4/32
    cni.projectcalico.org/podIPs: 172.17.1.4/32
  creationTimestamp: "2025-04-20T05:09:00Z"
  labels:
    run: lp-pod
  name: lp-pod
  namespace: low-priority
  resourceVersion: "1843"
  uid: 0a29f7bd-5cd3-4c10-aa0e-350a8b1dbda3
spec:
  priorityClassName: low-priority
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: lp-pod
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-m4j2h
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: node01
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-m4j2h
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2025-04-20T05:09:02Z"
    status: "True"
    type: PodReadyToStartContainers
  - lastProbeTime: null
    lastTransitionTime: "2025-04-20T05:09:00Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2025-04-20T05:09:02Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2025-04-20T05:09:02Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2025-04-20T05:09:00Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: containerd://f4668a6c815d94d515c8a92c10652f7ee9659cd2b5c3e39ecf5a0ebd6ec5c628
    image: docker.io/library/nginx:latest
    imageID: docker.io/library/nginx@sha256:5ed8fcc66f4ed123c1b2560ed708dc148755b6e4cbd8b943fab094f2c6bfa91e
    lastState: {}
    name: lp-pod
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2025-04-20T05:09:01Z"
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-m4j2h
      readOnly: true
      recursiveReadOnly: Disabled
  hostIP: 192.168.81.5
  hostIPs:
  - ip: 192.168.81.5
  phase: Running
  podIP: 172.17.1.4
  podIPs:
  - ip: 172.17.1.4
  qosClass: BestEffort
  startTime: "2025-04-20T05:09:00Z"

I am also facing same problem from Practice Test.Please somebody assist

You can’t set both “priorityClassName” and “priority” in the same pod, which is what your problem is. Note that the lp-pod has “priority: 0” already set, which contradicts what you are trying to do with priorityClassName.

3 Likes

Thanks Rob for the explanation.Will keep that in mind going forward

Thanks @rob_kodekloud for the explanation. Please close this thread.

Regards,
Sakshi