|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * nodes/scheduling/nodes-scheduler-node-affinity.adoc |
| 4 | +// * nodes/scheduling/nodes-scheduler-pod-affinity.adoc |
| 5 | +// * operators/admin/olm-adding-operators-to-cluster.adoc |
| 6 | + |
| 7 | +ifeval::["{context}" == "nodes-scheduler-pod-affinity"] |
| 8 | +:pod: |
| 9 | +endif::[] |
| 10 | +ifeval::["{context}" == "nodes-scheduler-node-affinity"] |
| 11 | +:node: |
| 12 | +endif::[] |
| 13 | +ifeval::["{context}" == "olm-adding-operators-to-a-cluster"] |
| 14 | +:olm: |
| 15 | +endif::[] |
| 16 | + |
| 17 | +:_content-type: PROCEDURE |
| 18 | +[id="olm-overriding-operator-pod-affinity_{context}"] |
| 19 | + |
| 20 | +ifdef::olm[] |
| 21 | += Controlling where an Operator is installed |
| 22 | +endif::olm[] |
| 23 | + |
| 24 | +ifdef::pod[] |
| 25 | += Using pod affinity and anti-affinity to control where an Operator is installed |
| 26 | +endif::pod[] |
| 27 | + |
| 28 | +ifdef::node[] |
| 29 | += Using node affinity to control where an Operator is installed |
| 30 | +endif::node[] |
| 31 | + |
| 32 | +By default, when you install an Operator, {product-title} installs the Operator pod to one of your worker nodes randomly. However, there might be situations where you want that pod scheduled on a specific node or set of nodes. |
| 33 | + |
| 34 | +The following examples describe situations where you might want to schedule an Operator pod to a specific node or set of nodes: |
| 35 | + |
| 36 | +* If an Operator requires a particular platform, such as `amd64` or `arm64` |
| 37 | +* If an Operator requires a particular operating system, such as Linux or Windows |
| 38 | +* If you want Operators that work together scheduled on the same host or on hosts located on the same rack |
| 39 | +* If you want Operators dispersed throughout the infrastructure to avoid downtime due to network or hardware issues |
| 40 | +
|
| 41 | +ifdef::olm[] |
| 42 | +You can control where an Operator pod is installed by adding node affinity, pod affinity, or pod anti-affinity constraints to the Operator's `Subscription` object. Node affinity is a set of rules used by the scheduler to determine where a pod can be placed. Pod affinity enables you to ensure that related pods are scheduled to the same node. Pod anti-affinity allows you to prevent a pod from being scheduled on a node. |
| 43 | +endif::olm[] |
| 44 | + |
| 45 | +ifdef::pod[] |
| 46 | +You can control where an Operator pod is installed by adding a pod affinity or anti-affinity to the Operator's `Subscription` object. |
| 47 | +endif::pod[] |
| 48 | + |
| 49 | +ifdef::node[] |
| 50 | +You can control where an Operator pod is installed by adding a node affinity constraints to the Operator's `Subscription` object. |
| 51 | +endif::node[] |
| 52 | + |
| 53 | +ifdef::olm[] |
| 54 | +The following examples show how to use node affinity or pod anti-affinity to install an instance of the Custom Metrics Autoscaler Operator to a specific node in the cluster: |
| 55 | +endif::olm[] |
| 56 | +ifdef::node[] |
| 57 | +The following examples show how to use node affinity to install an instance of the Custom Metrics Autoscaler Operator to a specific node in the cluster: |
| 58 | +endif::node[] |
| 59 | + |
| 60 | +ifndef::pod[] |
| 61 | +.Node affinity example that places the Operator pod on a specific node |
| 62 | +[source,terminal] |
| 63 | +---- |
| 64 | +apiVersion: operators.coreos.com/v1alpha1 |
| 65 | +kind: Subscription |
| 66 | +metadata: |
| 67 | + name: openshift-custom-metrics-autoscaler-operator |
| 68 | + namespace: openshift-keda |
| 69 | +spec: |
| 70 | + name: my-package |
| 71 | + source: my-operators |
| 72 | + sourceNamespace: operator-registries |
| 73 | + config: |
| 74 | + affinity: |
| 75 | + nodeAffinity: <1> |
| 76 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 77 | + nodeSelectorTerms: |
| 78 | + - matchExpressions: |
| 79 | + - key: kubernetes.io/hostname |
| 80 | + operator: In |
| 81 | + values: |
| 82 | + - ip-10-0-163-94.us-west-2.compute.internal |
| 83 | + ... |
| 84 | +---- |
| 85 | +<1> A node affinity that requires the Operator's pod to be scheduled on a node named `ip-10-0-163-94.us-west-2.compute.internal`. |
| 86 | + |
| 87 | +.Node affinity example that places the Operator pod on a node with a specific platform |
| 88 | +[source,terminal] |
| 89 | +---- |
| 90 | +apiVersion: operators.coreos.com/v1alpha1 |
| 91 | +kind: Subscription |
| 92 | +metadata: |
| 93 | + name: openshift-custom-metrics-autoscaler-operator |
| 94 | + namespace: openshift-keda |
| 95 | +spec: |
| 96 | + name: my-package |
| 97 | + source: my-operators |
| 98 | + sourceNamespace: operator-registries |
| 99 | + config: |
| 100 | + affinity: |
| 101 | + nodeAffinity: <1> |
| 102 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 103 | + nodeSelectorTerms: |
| 104 | + - matchExpressions: |
| 105 | + - key: kubernetes.io/arch |
| 106 | + operator: In |
| 107 | + values: |
| 108 | + - arm64 |
| 109 | + - key: kubernetes.io/os |
| 110 | + operator: In |
| 111 | + values: |
| 112 | + - linux |
| 113 | +---- |
| 114 | +<1> A node affinity that requires the Operator's pod to be scheduled on a node with the `kubernetes.io/arch=arm64` and `kubernetes.io/os=linux` labels. |
| 115 | +endif::pod[] |
| 116 | + |
| 117 | +ifdef::pod[] |
| 118 | +The following example shows how to use pod anti-affinity to prevent the installation the Custom Metrics Autoscaler Operator from any node that has pods with a specific label: |
| 119 | +endif::pod[] |
| 120 | + |
| 121 | +ifndef::node[] |
| 122 | +.Pod affinity example that places the Operator pod on one or more specific nodes |
| 123 | +[source,terminal] |
| 124 | +---- |
| 125 | +apiVersion: operators.coreos.com/v1alpha1 |
| 126 | +kind: Subscription |
| 127 | +metadata: |
| 128 | + name: openshift-custom-metrics-autoscaler-operator |
| 129 | + namespace: openshift-keda |
| 130 | +spec: |
| 131 | + name: my-package |
| 132 | + source: my-operators |
| 133 | + sourceNamespace: operator-registries |
| 134 | + config: |
| 135 | + affinity: |
| 136 | + podAffinity: |
| 137 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 138 | + - labelSelector: |
| 139 | + matchExpressions: |
| 140 | + - key: app |
| 141 | + operator: In |
| 142 | + values: |
| 143 | + - test |
| 144 | + topologyKey: kubernetes.io/hostname |
| 145 | +---- |
| 146 | +<1> A pod affinity that places the Operator's pod on a node that has pods with the `app=test` label. |
| 147 | + |
| 148 | +.Pod anti-affinity example that prevents the Operator pod from one or more specific nodes |
| 149 | +[source,terminal] |
| 150 | +---- |
| 151 | +apiVersion: operators.coreos.com/v1alpha1 |
| 152 | +kind: Subscription |
| 153 | +metadata: |
| 154 | + name: openshift-custom-metrics-autoscaler-operator |
| 155 | + namespace: openshift-keda |
| 156 | +spec: |
| 157 | + name: my-package |
| 158 | + source: my-operators |
| 159 | + sourceNamespace: operator-registries |
| 160 | + config: |
| 161 | + affinity: |
| 162 | + podAntiAffinity: <1> |
| 163 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 164 | + - labelSelector: |
| 165 | + matchExpressions: |
| 166 | + - key: cpu |
| 167 | + operator: In |
| 168 | + values: |
| 169 | + - high |
| 170 | + topologyKey: kubernetes.io/hostname |
| 171 | + ... |
| 172 | +---- |
| 173 | +<1> A pod anti-affinity that prevents the Operator's pod from being scheduled on a node that has pods with the `cpu=high` label. |
| 174 | +endif::node[] |
| 175 | + |
| 176 | +.Procedure |
| 177 | + |
| 178 | +To control the placement of an Operator pod, complete the following steps: |
| 179 | + |
| 180 | +. Install the Operator as usual. |
| 181 | + |
| 182 | +. If needed, ensure that your nodes are labeled to properly respond to the affinity. |
| 183 | + |
| 184 | +. Edit the Operator `Subscription` object to add an affinity: |
| 185 | ++ |
| 186 | +ifndef::pod[] |
| 187 | +[source,terminal] |
| 188 | +---- |
| 189 | +apiVersion: operators.coreos.com/v1alpha1 |
| 190 | +kind: Subscription |
| 191 | +metadata: |
| 192 | + name: openshift-custom-metrics-autoscaler-operator |
| 193 | + namespace: openshift-keda |
| 194 | +spec: |
| 195 | + name: my-package |
| 196 | + source: my-operators |
| 197 | + sourceNamespace: operator-registries |
| 198 | + config: |
| 199 | + affinity: <1> |
| 200 | + nodeAffinity: |
| 201 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 202 | + nodeSelectorTerms: |
| 203 | + - matchExpressions: |
| 204 | + - key: kubernetes.io/hostname |
| 205 | + operator: In |
| 206 | + values: |
| 207 | + - ip-10-0-185-229.ec2.internal |
| 208 | + ... |
| 209 | +---- |
| 210 | +ifdef::olm[] |
| 211 | +<1> Add a `nodeAffinity`, `podAffinity`, or `podAntiAffinity`. See the Additional resources section that follows for information about creating the affinity. |
| 212 | +endif::[] |
| 213 | +ifdef::node[] |
| 214 | +<1> Add a `nodeAffinity`. |
| 215 | +endif::[] |
| 216 | +endif::pod[] |
| 217 | +ifdef::pod[] |
| 218 | +[source,terminal] |
| 219 | +---- |
| 220 | +apiVersion: operators.coreos.com/v1alpha1 |
| 221 | +kind: Subscription |
| 222 | +metadata: |
| 223 | + name: openshift-custom-metrics-autoscaler-operator |
| 224 | + namespace: openshift-keda |
| 225 | +spec: |
| 226 | + name: my-package |
| 227 | + source: my-operators |
| 228 | + sourceNamespace: operator-registries |
| 229 | + config: |
| 230 | + affinity: |
| 231 | + podAntiAffinity: <1> |
| 232 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 233 | + podAffinityTerm: |
| 234 | + labelSelector: |
| 235 | + matchExpressions: |
| 236 | + - key: kubernetes.io/hostname |
| 237 | + operator: In |
| 238 | + values: |
| 239 | + - ip-10-0-185-229.ec2.internal |
| 240 | + topologyKey: topology.kubernetes.io/zone |
| 241 | + ... |
| 242 | +---- |
| 243 | +<1> Add a `podAffinity` or `podAntiAffinity`. |
| 244 | +endif::pod[] |
| 245 | + |
| 246 | +.Verification |
| 247 | + |
| 248 | +* To ensure that the pod is deployed on the specific node, run the following command: |
| 249 | ++ |
| 250 | +[source,terminal] |
| 251 | +---- |
| 252 | +$ oc get pods -o wide |
| 253 | +---- |
| 254 | ++ |
| 255 | +.Example output |
| 256 | ++ |
| 257 | +---- |
| 258 | +NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES |
| 259 | +custom-metrics-autoscaler-operator-5dcc45d656-bhshg 1/1 Running 0 50s 10.131.0.20 ip-10-0-185-229.ec2.internal <none> <none> |
| 260 | +---- |
| 261 | +
|
| 262 | +ifeval::["{context}" == "nodes-scheduler-pod-affinity"] |
| 263 | +:!pod: |
| 264 | +endif::[] |
| 265 | +ifeval::["{context}" == "nodes-scheduler-node-affinity"] |
| 266 | +:!node: |
| 267 | +endif::[] |
| 268 | +ifeval::["{context}" == "olm-adding-operators-to-a-cluster"] |
| 269 | +:!olm: |
| 270 | +endif::[] |
0 commit comments