默认情况下,安装 Operator 时,Red Hat OpenShift Service on AWS 会将 Operator Pod 随机安装到您的某个工作节点上。但是,在某些情况下,您可能希望将该 Pod 调度到特定节点或节点集。
以下示例描述了您可能希望将 Operator Pod 调度到特定节点或节点集的情况
您可以通过向 Operator 的 Subscription
对象添加节点亲和性、Pod 亲和性或 Pod 反亲和性约束来控制 Operator Pod 的安装位置。节点亲和性是一组规则,调度程序使用这些规则来确定 Pod 的部署位置。Pod 亲和性使您可以确保将相关的 Pod 调度到同一节点。Pod 反亲和性允许您防止 Pod 被调度到节点上。
以下示例展示了如何使用节点亲和性或 Pod 反亲和性将 Custom Metrics Autoscaler Operator 的实例安装到集群中的特定节点
将 Operator Pod 部署到特定节点的节点亲和性示例
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-custom-metrics-autoscaler-operator
namespace: openshift-keda
spec:
name: my-package
source: my-operators
sourceNamespace: operator-registries
config:
affinity:
nodeAffinity: (1)
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- ip-10-0-163-94.us-west-2.compute.internal
#...
1 |
需要将 Operator 的 Pod 调度到名为 ip-10-0-163-94.us-west-2.compute.internal 的节点的节点亲和性。 |
将 Operator Pod 部署到具有特定平台的节点的节点亲和性示例
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-custom-metrics-autoscaler-operator
namespace: openshift-keda
spec:
name: my-package
source: my-operators
sourceNamespace: operator-registries
config:
affinity:
nodeAffinity: (1)
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
- arm64
- key: kubernetes.io/os
operator: In
values:
- linux
#...
1 |
需要将 Operator 的 Pod 调度到具有 kubernetes.io/arch=arm64 和 kubernetes.io/os=linux 标签的节点的节点亲和性。 |
将 Operator Pod 部署到一个或多个特定节点的 Pod 亲和性示例
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-custom-metrics-autoscaler-operator
namespace: openshift-keda
spec:
name: my-package
source: my-operators
sourceNamespace: operator-registries
config:
affinity:
podAffinity: (1)
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- test
topologyKey: kubernetes.io/hostname
#...
1 |
将 Operator 的 Pod 部署到具有 app=test 标签的 Pod 所在节点的 Pod 亲和性。 |
防止 Operator Pod 部署到一个或多个特定节点的 Pod 反亲和性示例
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-custom-metrics-autoscaler-operator
namespace: openshift-keda
spec:
name: my-package
source: my-operators
sourceNamespace: operator-registries
config:
affinity:
podAntiAffinity: (1)
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: cpu
operator: In
values:
- high
topologyKey: kubernetes.io/hostname
#...
1 |
防止 Operator 的 Pod 被调度到具有 cpu=high 标签的 Pod 所在节点的 Pod 反亲和性。 |
步骤
要控制 Operator Pod 的部署位置,请完成以下步骤
-
照常安装 Operator。
-
如果需要,请确保您的节点已标记,以便正确响应亲和性。
-
编辑 Operator Subscription
对象以添加亲和性
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: openshift-custom-metrics-autoscaler-operator
namespace: openshift-keda
spec:
name: my-package
source: my-operators
sourceNamespace: operator-registries
config:
affinity: (1)
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- ip-10-0-185-229.ec2.internal
#...
1 |
添加 nodeAffinity 、podAffinity 或 podAntiAffinity 。有关创建亲和性的信息,请参阅以下的“附加资源”部分。 |
验证
-
要确保 Pod 部署在特定节点上,请运行以下命令
示例输出
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
custom-metrics-autoscaler-operator-5dcc45d656-bhshg 1/1 Running 0 50s 10.131.0.20 ip-10-0-185-229.ec2.internal <none> <none>