:_mod-docs-content-type: PROCEDURE

// Module included in the following assemblies:
//
// assembly-scheduling.adoc

[id='proc-dedicated-nodes-{context}']
= Configuring pod scheduling for dedicated nodes

[role="_abstract"]
You can dedicate a set of worker nodes exclusively to your Kafka brokers so that no other applications can compete with Kafka for resources on those nodes.

To configure dedicated worker nodes for Kafka pods in a specific pool, combine the following:

Taints:: Apply taints to worker nodes to prevent other pods from being scheduled on them.
Tolerations:: Apply tolerations to Kafka pods to allow them to be scheduled on tainted nodes.
Affinity:: Apply affinity to Kafka pods to schedule them on specifically labeled nodes.

This procedure provides configuration examples for the cluster-wide `Kafka` resource and the pool-specific `KafkaNodePool` resource.

NOTE: If a property is defined in both `KafkaNodePool.spec.template` and `Kafka.spec.kafka.template`, the property defined in the node pool is used.
Properties are not merged. 
For more information, see xref:affinity-{context}[Scheduling strategies].

.Prerequisites

* xref:deploying-cluster-operator-str[The Cluster Operator must be deployed.] 
* Dedicated worker nodes without scheduled workloads

.Procedure

. Taint and label the dedicated worker nodes to prevent other pods from being scheduled on them and to identify them when scheduling the Kafka pods:
+
[source,shell]
----
kubectl taint node <name_of_node> dedicated=kafka:NoSchedule
kubectl label node <name_of_node> dedicated=kafka
----

. Configure `tolerations` and `nodeAffinity` in either your `Kafka` or `KafkaNodePool` custom resource to match the taint and label.
+
--
* To set a cluster-wide rule, edit the `affinity` property in `spec.kafka.template.pod` of your `Kafka` resource.
* To set a pool-specific rule, edit the `affinity` property in `spec.template.pod` of your `KafkaNodePool` resource.
--
+
In both cases, use `nodeSelectorTerms` with `matchExpressions` to specify the key-value label of the nodes you want to schedule pods on.
+
This example applies a rule to a `Kafka` resource that assigns all its broker pods to run only on nodes that have been tainted and labeled with `dedicated=kafka`.
+
.Example cluster-wide affinity configuration for dedicated nodes
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaApiVersion}
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    # ...
    template:
      pod:
        tolerations:
          - key: "dedicated"
            operator: "Equal"
            value: "kafka"
            effect: "NoSchedule"
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
              - matchExpressions:
                - key: dedicated
                  operator: In
                  values:
                  - kafka
  # ...
----
+
This example applies a rule to a `KafkaNodePool` resource named `broker` that assigns its pods to run on dedicated nodes marked with `dedicated=broker-kafka`.
+
.Example node pool-specific affinity configuration for dedicated nodes
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaNodePoolApiVersion}
kind: KafkaNodePool
metadata:
  name: broker
  labels:
    strimzi.io/cluster: my-cluster
spec:
  replicas: 3
  roles:
    - broker
  template:
    pod:
      tolerations:
        - key: "dedicated"
          operator: "Equal"
          value: "kafka"
          effect: "NoSchedule"
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: dedicated
                operator: In
                values:
                - broker-kafka
  # ...
----

. Apply the changes to your custom resource configuration.