mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
137 lines
4.1 KiB
Plaintext
137 lines
4.1 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * nodes/nodes-pods-priority.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="nodes-pods-priority-configuring_{context}"]
|
|
= Configuring priority and preemption
|
|
|
|
You apply pod priority and preemption by creating a priority class object and associating pods to the priority by using the
|
|
`priorityClassName` in your pod specs.
|
|
|
|
[NOTE]
|
|
====
|
|
You cannot add a priority class directly to an existing scheduled pod.
|
|
====
|
|
|
|
.Procedure
|
|
|
|
To configure your cluster to use priority and preemption:
|
|
|
|
ifndef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
. Create one or more priority classes:
|
|
|
|
.. Create a YAML file similar to the following:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: scheduling.k8s.io/v1
|
|
kind: PriorityClass
|
|
metadata:
|
|
name: high-priority <1>
|
|
value: 1000000 <2>
|
|
preemptionPolicy: PreemptLowerPriority <3>
|
|
globalDefault: false <4>
|
|
description: "This priority class should be used for XYZ service pods only." <5>
|
|
----
|
|
<1> The name of the priority class object.
|
|
<2> The priority value of the object.
|
|
<3> Optional. Specifies whether this priority class is preempting or non-preempting. The preemption policy defaults to `PreemptLowerPriority`, which allows pods of that priority class to preempt lower-priority pods. If the preemption policy is set to `Never`, pods in that priority class are non-preempting.
|
|
<4> Optional. Specifies whether this priority class should be used for pods without a priority class name specified. This field is `false` by default. Only one priority class with `globalDefault` set to `true` can exist in the cluster. If there is no priority class with `globalDefault:true`, the priority of pods with no priority class name is zero. Adding a priority class with `globalDefault:true` affects only pods created after the priority class is added and does not change the priorities of existing pods.
|
|
<5> Optional. Describes which pods developers should use with this priority class. Enter an arbitrary text string.
|
|
|
|
.. Create the priority class:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <file-name>.yaml
|
|
----
|
|
|
|
. Create a pod spec to include the name of a priority class:
|
|
// ROSA/OSD cannot create new priority classes. Must use the defaults.
|
|
.. Create a YAML file similar to the following:
|
|
+
|
|
ifndef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: nginx
|
|
labels:
|
|
env: test
|
|
spec:
|
|
securityContext:
|
|
runAsNonRoot: true
|
|
seccompProfile:
|
|
type: RuntimeDefault
|
|
containers:
|
|
- name: nginx
|
|
image: nginx
|
|
imagePullPolicy: IfNotPresent
|
|
securityContext:
|
|
allowPrivilegeEscalation: false
|
|
capabilities:
|
|
drop: [ALL]
|
|
priorityClassName: high-priority <1>
|
|
----
|
|
<1> Specify the priority class to use with this pod.
|
|
endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
ifdef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: nginx
|
|
labels:
|
|
env: test
|
|
spec:
|
|
containers:
|
|
- name: nginx
|
|
image: nginx
|
|
imagePullPolicy: IfNotPresent
|
|
priorityClassName: system-cluster-critical <1>
|
|
----
|
|
<1> Specify the priority class to use with this pod.
|
|
endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
|
|
.. Create the pod:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <file-name>.yaml
|
|
----
|
|
endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
|
|
ifdef::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
// ROSA/OSD cannot create new priority classes. Must use the defaults.
|
|
. Define a pod spec to include the name of a priority class by creating a YAML file similar to the following:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: nginx
|
|
labels:
|
|
env: test
|
|
spec:
|
|
containers:
|
|
- name: nginx
|
|
image: nginx
|
|
imagePullPolicy: IfNotPresent
|
|
priorityClassName: system-cluster-critical <1>
|
|
----
|
|
<1> Specify the priority class to use with this pod.
|
|
|
|
. Create the pod:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <file-name>.yaml
|
|
----
|
|
endif::openshift-rosa,openshift-rosa-hcp,openshift-dedicated[]
|
|
+
|
|
You can add the priority name directly to the pod configuration or to a pod template.
|