Search code examples
kuberneteskubectlkubernetes-podpod-priority

How does priorityClass Works


I try to use priorityClass.

I create two pods, the first has system-node-critical priority and the second cluster-node-critical priority.

Both pods need to run in a node labeled with nodeName: k8s-minion1 but such a node has only 2 cpus while both pods request 1.5 cpu. I then expect that the second pod runs and the first is in pending status. Instead, the first pod always runs no matter the classpriority I affect to the second pod.

I even tried to label the node afted I apply my manifest but does not change anything.

Here is my manifest :

apiVersion: v1
kind: Pod
metadata:
  name: firstpod
spec:
  containers:
  - name: container
    image: nginx
    resources:
      requests:
        cpu: 1.5
  nodeSelector:
    nodeName: k8s-minion1
  priorityClassName: cluster-node-critical
---
apiVersion: v1
kind: Pod
metadata:
  name: secondpod
spec:
  containers:
  - name: container
    image: nginx
    resources:
      requests:
        cpu: 1.5
  priorityClassName: system-node-critical
  nodeSelector:
    nodeName: k8s-minion1

It is worth noting that I get an error "unknown object : priorityclass" when I do kubectl get priorityclass and when I export my running pod in yml with kubectl get pod secondpod -o yaml, I cant find any classpriority: field.

Here Are my version infos:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"} 
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0+coreos.0", GitCommit:"6bb2e725fc2876cd94b3900fc57a1c98ca87a08b", GitTreeState:"clean", BuildDate:"2018-04-02T16:49:31Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

Any ideas why this is not working?

Thanks in advance,

Abdelghani


Solution

  • PriorityClasses first appeared in k8s 1.8 as alpha feature. It graduated to beta in 1.11

    You are using 1.10 and this means that this feature is in alpha.

    Alpha features are not enabled by default so you would need to enable it.

    Unfortunately k8s version 1.10 is no longer supported, so I'd suggest to upgrade at least to 1.14 where priorityClass feature became stable.