|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * networking/metallb/metallb-operator-install.adoc |
| 4 | + |
| 5 | +[id="nw-metallb-operator-setting-pod-priority-affinity_{context}"] |
| 6 | += Configuring pod priority and pod affinity in a MetalLB deployment |
| 7 | + |
| 8 | +You can optionally assign pod priority and pod affinity rules to `controller` and `speaker` pods by configuring the `MetalLB` custom resource. The pod priority indicates the relative importance of a pod on a node and schedules the pod based on this priority. Set a high priority on your `controller` or `speaker` pod to ensure scheduling priority over other pods on the node. |
| 9 | + |
| 10 | +Pod affinity manages relationships among pods. Assign pod affinity to the `controller` or `speaker` pods to control on what node the scheduler places the pod in the context of pod relationships. For example, you can allow pods with logically related workloads on the same node, or ensure pods with conflicting workloads are on separate nodes. |
| 11 | + |
| 12 | +.Prerequisites |
| 13 | + |
| 14 | +* You are logged in as a user with `cluster-admin` privileges. |
| 15 | + |
| 16 | +* You have installed the MetalLB Operator. |
| 17 | + |
| 18 | +.Procedure |
| 19 | +. Create a `PriorityClass` custom resource, such as `myPriorityClass.yaml`, to configure the priority level. This example uses a high-priority class: |
| 20 | ++ |
| 21 | +[source,yaml] |
| 22 | +---- |
| 23 | +apiVersion: scheduling.k8s.io/v1 |
| 24 | +kind: PriorityClass |
| 25 | +metadata: |
| 26 | + name: high-priority |
| 27 | +value: 1000000 |
| 28 | +---- |
| 29 | + |
| 30 | +. Apply the `PriorityClass` custom resource configuration: |
| 31 | ++ |
| 32 | +[source,bash] |
| 33 | +---- |
| 34 | +$ oc apply -f myPriorityClass.yaml |
| 35 | +---- |
| 36 | + |
| 37 | +. Create a `MetalLB` custom resource, such as `MetalLBPodConfig.yaml`, to specify the `priorityClassName` and `podAffinity` values: |
| 38 | ++ |
| 39 | +[source,yaml] |
| 40 | +---- |
| 41 | +apiVersion: metallb.io/v1beta1 |
| 42 | +kind: MetalLB |
| 43 | +metadata: |
| 44 | + name: metallb |
| 45 | + namespace: metallb-system |
| 46 | +spec: |
| 47 | + logLevel: debug |
| 48 | + controllerConfig: |
| 49 | + priorityClassName: high-priority |
| 50 | + runtimeClassName: myclass |
| 51 | + speakerConfig: |
| 52 | + priorityClassName: high-priority |
| 53 | + runtimeClassName: myclass |
| 54 | + affinity: |
| 55 | + podAffinity: |
| 56 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 57 | + - labelSelector: |
| 58 | + matchLabels: |
| 59 | + app: metallb |
| 60 | + topologyKey: kubernetes.io/hostname |
| 61 | +---- |
| 62 | + |
| 63 | +. Apply the `MetalLB` custom resource configuration: |
| 64 | ++ |
| 65 | +[source,bash] |
| 66 | +---- |
| 67 | +$ oc apply -f MetalLBPodConfig.yaml |
| 68 | +---- |
| 69 | + |
| 70 | +.Verification |
| 71 | +* To view the priority class that you assigned to pods in a namespace, run the following command, replacing `<namespace>` with your target namespace: |
| 72 | ++ |
| 73 | +[source,bash] |
| 74 | +---- |
| 75 | +$ oc get pods -n <namespace> -o custom-columns=NAME:.metadata.name,PRIORITY:.spec.priorityClassName |
| 76 | +---- |
| 77 | + |
| 78 | +* To verify that the scheduler placed pods according to pod affinity rules, view the metadata for the pod's node by running the following command, replacing `<namespace>` with your target namespace: |
| 79 | ++ |
| 80 | +[source,bash] |
| 81 | +---- |
| 82 | +$ oc get pod -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name -n <namespace> |
| 83 | +---- |
0 commit comments