|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * operators/operator_sdk/osdk-multi-arch-support.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="osdk-multi-arch-node-reqs_{context}"] |
| 7 | += Using required node affinity rules to support multi-architecture compute machines for Operator projects |
| 8 | + |
| 9 | +If you want your Operator to support multi-architecture compute machines, you must define your Operator's required node affinity rules. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* An Operator project created or maintained with Operator SDK {osdk_ver} or later. |
| 14 | +* A manifest list defining the platforms your Operator supports. |
| 15 | +
|
| 16 | +.Procedure |
| 17 | + |
| 18 | +. Search your Operator project for Kubernetes manifests that define pod spec and pod template spec objects. |
| 19 | ++ |
| 20 | +[IMPORTANT] |
| 21 | +==== |
| 22 | +Because object type names are not declared in YAML files, look for the mandatory `containers` field in your Kubernetes manifests. The `containers` field is required when specifying both pod spec and pod template spec objects. |
| 23 | + |
| 24 | +You must set node affinity rules in all Kubernetes manifests that define a pod spec or pod template spec, including objects such as `Pod`, `Deployment`, `DaemonSet`, and `StatefulSet`. |
| 25 | +==== |
| 26 | ++ |
| 27 | +.Example Kubernetes manifest |
| 28 | +[source,yaml] |
| 29 | +---- |
| 30 | +apiVersion: v1 |
| 31 | +kind: Pod |
| 32 | +metadata: |
| 33 | + name: s1 |
| 34 | +spec: |
| 35 | + containers: |
| 36 | + - name: <container_name> |
| 37 | + image: docker.io/<org>/<image_name> |
| 38 | +---- |
| 39 | + |
| 40 | +. Set the required node affinity rules in the Kubernetes manifests that define pod spec and pod template spec objects, similar to the following example: |
| 41 | ++ |
| 42 | +.Example Kubernetes manifest |
| 43 | +[source,yaml] |
| 44 | +---- |
| 45 | +apiVersion: v1 |
| 46 | +kind: Pod |
| 47 | +metadata: |
| 48 | + name: s1 |
| 49 | +spec: |
| 50 | + containers: |
| 51 | + - name: <container_name> |
| 52 | + image: docker.io/<org>/<image_name> |
| 53 | + affinity: |
| 54 | + nodeAffinity: |
| 55 | + requiredDuringSchedulingIgnoredDuringExecution: <1> |
| 56 | + nodeSelectorTerms: <2> |
| 57 | + - matchExpressions: <3> |
| 58 | + - key: kubernetes.io/arch <4> |
| 59 | + operator: In |
| 60 | + values: |
| 61 | + - amd64 |
| 62 | + - arm64 |
| 63 | + - ppc64le |
| 64 | + - s390x |
| 65 | + - key: kubernetes.io/os <5> |
| 66 | + operator: In |
| 67 | + values: |
| 68 | + - linux |
| 69 | +---- |
| 70 | +<1> Defines a required rule. |
| 71 | +<2> If you specify multiple `nodeSelectorTerms` associated with `nodeAffinity` types, then the pod can be scheduled onto a node if one of the `nodeSelectorTerms` is satisfied. |
| 72 | +<3> If you specify multiple `matchExpressions` associated with `nodeSelectorTerms`, then the pod can be scheduled onto a node only if all `matchExpressions` are satisfied. |
| 73 | +<4> Specifies the architectures defined in the manifest list. |
| 74 | +<5> Specifies the operating systems defined in the manifest list. |
| 75 | + |
| 76 | +. Go-based Operator projects that use dynamically created workloads might embed pod spec and pod template spec objects in the Operator's logic. |
| 77 | ++ |
| 78 | +If your project embeds pod spec or pod template spec objects in the Operator's logic, edit your Operator's logic similar to the following example. The following example shows how to update a `PodSpec` object by using the Go API: |
| 79 | ++ |
| 80 | +[source,go] |
| 81 | +---- |
| 82 | +Template: corev1.PodTemplateSpec{ |
| 83 | + ... |
| 84 | + Spec: corev1.PodSpec{ |
| 85 | + Affinity: &corev1.Affinity{ |
| 86 | + NodeAffinity: &corev1.NodeAffinity{ |
| 87 | + RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{ |
| 88 | + NodeSelectorTerms: []corev1.NodeSelectorTerm{ |
| 89 | + { |
| 90 | + MatchExpressions: []corev1.NodeSelectorRequirement{ |
| 91 | + { |
| 92 | + Key: "kubernetes.io/arch", |
| 93 | + Operator: "In", |
| 94 | + Values: []string{"amd64","arm64","ppc64le","s390x"}, |
| 95 | + }, |
| 96 | + { |
| 97 | + Key: "kubernetes.io/os", |
| 98 | + Operator: "In", |
| 99 | + Values: []string{"linux"}, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + SecurityContext: &corev1.PodSecurityContext{ |
| 108 | + ... |
| 109 | + }, |
| 110 | + Containers: []corev1.Container{{ |
| 111 | + ... |
| 112 | + }}, |
| 113 | + }, |
| 114 | +---- |
| 115 | ++ |
| 116 | +where: |
| 117 | + |
| 118 | +`RequiredDuringSchedulingIgnoredDuringExecution`:: Defines a required rule. |
| 119 | +`NodeSelectorTerms`:: If you specify multiple `nodeSelectorTerms` associated with `nodeAffinity` types, then the pod can be scheduled onto a node if one of the `nodeSelectorTerms` is satisfied. |
| 120 | +`MatchExpressions`:: If you specify multiple `matchExpressions` associated with `nodeSelectorTerms`, then the pod can be scheduled onto a node only if all `matchExpressions` are satisfied. |
| 121 | +`kubernetes.io/arch`:: Specifies the architectures defined in the manifest list. |
| 122 | +`kubernetes.io/os`:: Specifies the operating systems defined in the manifest list. |
| 123 | + |
| 124 | +[WARNING] |
| 125 | +==== |
| 126 | +If you do not set node affinity rules and a container is scheduled to a compute machine with an incompatible architecture, the pod fails and triggers one of the following events: |
| 127 | +
|
| 128 | +`CrashLoopBackOff`:: Occurs when an image manifest's entry point fails to run and an `exec format error` message is printed in the logs. |
| 129 | +`ImagePullBackOff`:: Occurs when a manifest list does not include a manifest for the architecture where a pod is scheduled or the node affinity terms are set to the wrong values. |
| 130 | +==== |
0 commit comments