<p>I know what Priority class are in k8s but could not find anything about priority object after lot of searching.</p>

<p>So problem is I have created a PriorityClass object in my k8s cluster and set its value to -100000 and have created a pod with this priorityClass. Now when I do kubectl describe Pod I am getting two different field </p>

<pre><code>Priority:           0

PriorityClassName:  imagebuild-priority
</code></pre>

<p>My admission-controller throws the following error</p>

<pre><code>Error from server (Forbidden): error when creating "/tmp/tmp.4tJSpSU0dy/app.yml": 
pods "pod-name" is forbidden: the integer value of priority (0) must not be provided in pod spec; 
priority admission controller computed -1000000 from the given PriorityClass name
</code></pre>

<p>Somewhere it is setting Priority to 0 and PriorityClass trying to set it to -10000.</p>

<p>PriorityClass object has globalDefault: False</p>

<p>Command Run </p>

<p><code>kubectl create -f app.yml</code></p>

<p>Yaml file</p>

<pre><code>---
apiVersion: v1
kind: Pod
metadata:
  name: image-builder-serviceacc
spec:
  securityContext:
    runAsUser: 0
  serviceAccountName: {{ serviceaccount }}
  automountServiceAccountToken: false
  containers:
  - name: container
    image: ....
    imagePullPolicy: Always
    env:
    - name: PATH
      value: "$PATH:/bin:/busybox/"
    command: [ "sh", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ]
  initContainers:
  - name: init-container
    image: ....
    imagePullPolicy: Always
    env:
    - name: PATH
      value: "$PATH:/bin:/busybox/"
    command: [ "sh", "-c", "--" ]
    args: [ "ls" ]
  restartPolicy: Always

</code></pre>

<p>Mutating controlled will append PriorityClass</p>

prashant
<p>As per <a href="https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass" rel="nofollow noreferrer">documentation</a>:</p>

<blockquote>
  <p>PriorityClass also has two optional fields: globalDefault and description. The globalDefault field indicates that the value of this PriorityClass should be used for Pods without a priorityClassName. <strong>Only one PriorityClass with globalDefault set to true</strong> can exist in the system. If there is no PriorityClass with globalDefault set, the priority of Pods with no priorityClassName is zero.</p>
</blockquote>

<p>This error means that u have collision</p>

<pre><code>the integer value of priority (0) must not be provided in pod spec; 
priority admission controller computed -1000000 from the given PriorityClass name
</code></pre>

<p>You can fix it in 2 ways:</p>

<p>your should choose between <strong>globalDefault: true</strong> :</p>

<p>PriorityClass:</p>

<pre><code>apiVersion: scheduling.k8s.io/v1beta1
kind: PriorityClass
metadata:
  name: high-priority-minus
value: -2000000
globalDefault: True
description: "This priority class should be used for XYZ service pods only."
</code></pre>

<p>Pod:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx5
  labels:
    env: test
spec:
  containers:
  - name: nginx5
    image: nginx
    imagePullPolicy: IfNotPresent
  priorityClassName: high-priority-minus 
</code></pre>

<p>priorityClassName <strong>can be used here, but you dont need to</strong></p>

<p>Or with <strong>globalDefault: false</strong> :</p>

<p>You need to choose <strong>1 option,</strong> priorityClassName or priority in your pod as described in you'r message error.</p>

<p>PriorityClass:</p>

<pre><code>apiVersion: scheduling.k8s.io/v1beta1
kind: PriorityClass
metadata:
  name: high-priority
value: 1000000
globalDefault: false
description: "This priority class should be used for XYZ service pods only."
</code></pre>

<p>Pod:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx7
  labels:
    env: test
spec:
  containers:
  - name: nginx7
    image: nginx
    imagePullPolicy: IfNotPresent
  priorityClassName: high-priority
</code></pre>
