12.2. 使用污点和容限来控制日志记录 pod 放置
通过污点和容限,节点可以控制哪些 pod 应该(或不应该)调度到节点上。
12.2.1. 了解污点和容限 复制链接链接已复制到粘贴板!
通过使用污点(taint),节点可以拒绝调度 pod,除非 pod 具有匹配的容限(toleration)。
您可以通过节点规格(NodeSpec)将污点应用到节点,并通过 Pod 规格(PodSpec)将容限应用到 pod。当您应用污点时,调度程序无法将 pod 放置到该节点上,除非 pod 可以容限该污点。
节点规格中的污点示例
apiVersion: v1
kind: Node
metadata:
name: my-node
#...
spec:
taints:
- effect: NoExecute
key: key1
value: value1
#...
Pod 规格中的容限示例
apiVersion: v1
kind: Pod
metadata:
name: my-pod
#...
spec:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoExecute"
tolerationSeconds: 3600
#...
污点与容限由 key、value 和 effect 组成。
| 参数 | 描述 | ||||||
|---|---|---|---|---|---|---|---|
|
|
| ||||||
|
|
| ||||||
|
| effect 的值包括:
| ||||||
|
|
|
如果向 control plane 节点添加了一个
NoSchedule污点,节点必须具有node-role.kubernetes.io/master=:NoSchedule污点,这默认会添加。例如:
apiVersion: v1 kind: Node metadata: annotations: machine.openshift.io/machine: openshift-machine-api/ci-ln-62s7gtb-f76d1-v8jxv-master-0 machineconfiguration.openshift.io/currentConfig: rendered-master-cdc1ab7da414629332cc4c3926e6e59c name: my-node #... spec: taints: - effect: NoSchedule key: node-role.kubernetes.io/master #...
容限与污点匹配:
如果
operator参数设为Equal:-
key参数相同; -
value参数相同; -
effect参数相同。
-
如果
operator参数设为Exists:-
key参数相同; -
effect参数相同。
-
OpenShift Container Platform 中内置了以下污点:
-
node.kubernetes.io/not-ready:节点未就绪。这与节点状况Ready=False对应。 -
node.kubernetes.io/unreachable:节点无法从节点控制器访问。这与节点状况Ready=Unknown对应。 -
node.kubernetes.io/memory-pressure:节点存在内存压力问题。这与节点状况MemoryPressure=True对应。 -
node.kubernetes.io/disk-pressure:节点存在磁盘压力问题。这与节点状况DiskPressure=True对应。 -
node.kubernetes.io/network-unavailable:节点网络不可用。 -
node.kubernetes.io/unschedulable:节点不可调度。 -
node.cloudprovider.kubernetes.io/uninitialized:当节点控制器通过外部云提供商启动时,在节点上设置这个污点来将其标记为不可用。在云控制器管理器中的某个控制器初始化这个节点后,kubelet 会移除此污点。 node.kubernetes.io/pid-pressure:节点具有 pid 压力。这与节点状况PIDPressure=True对应。重要OpenShift Container Platform 不设置默认的 pid.available
evictionHard。
12.2.2. 使用容忍度来控制日志存储 pod 放置 复制链接链接已复制到粘贴板!
默认情况下,日志存储 pod 具有以下容限配置:
Elasticsearch 日志存储 pod 默认容限
apiVersion: v1
kind: Pod
metadata:
name: elasticsearch-example
namespace: openshift-logging
spec:
# ...
tolerations:
- effect: NoSchedule
key: node.kubernetes.io/disk-pressure
operator: Exists
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
- effect: NoSchedule
key: node.kubernetes.io/memory-pressure
operator: Exists
# ...
LokiStack 日志存储 pod 默认容限
apiVersion: v1
kind: Pod
metadata:
name: lokistack-example
namespace: openshift-logging
spec:
# ...
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
- effect: NoSchedule
key: node.kubernetes.io/memory-pressure
operator: Exists
# ...
您可以通过添加污点,然后在 ClusterLogging 自定义资源 (CR) 中修改 tolerations 语法,为日志存储 pod 配置容限。
先决条件
- 已安装 Red Hat OpenShift Logging Operator。
-
已安装 OpenShift CLI(
oc)。 - 您已部署了内部日志存储,可以是 Elasticsearch 或 LokiStack。
流程
运行以下命令,将污点添加到要在其上调度日志记录 pod 的节点:
$ oc adm taint nodes <node_name> <key>=<value>:<effect>示例命令
$ oc adm taint nodes node1 lokistack=node:NoExecute本例在
node1上放置一个键为lokistack的污点,值为node,污点效果是NoExecute。具有NoExecute效果的节点仅调度与污点匹配的 Pod,并删除不匹配的现有 pod。编辑
ClusterLoggingCR 的logstore部分,以配置日志存储 pod 的容忍度:ClusterLoggingCR 示例apiVersion: logging.openshift.io/v1 kind: ClusterLogging metadata: # ... spec: # ... logStore: type: lokistack elasticsearch: nodeCount: 1 tolerations: - key: lokistack1 operator: Exists2 effect: NoExecute3 tolerationSeconds: 60004 # ...
此容忍度与 oc adm taint 命令创建的污点匹配。具有此容忍度的 pod 可以调度到 node1 上。
12.2.3. 使用容忍度来控制日志可视化 pod 放置 复制链接链接已复制到粘贴板!
您可以使用不在其他 Pod 上的特定键/值对来确保只有 Kibana Pod 可以在指定节点上运行。
先决条件
-
已安装 Red Hat OpenShift Logging Operator、OpenShift Elasticsearch Operator 和 OpenShift CLI (
oc)。
流程
运行以下命令,将污点添加到要在其上调度日志可视化 pod 的节点:
$ oc adm taint nodes <node_name> <key>=<value>:<effect>示例命令
$ oc adm taint nodes node1 kibana=node:NoExecute本例在
node1上放置一个键为kibana且值为node的污点,污点效果是NoExecute。您必须使用NoExecute污点设置。NoExecute仅调度与污点匹配的 pod,并删除不匹配的现有 pod。编辑
ClusterLoggingCR 的visualization部分,以配置 Kibana pod 的容忍度:apiVersion: logging.openshift.io/v1 kind: ClusterLogging metadata: # ... spec: # ... visualization: type: kibana kibana: tolerations: - key: kibana1 operator: Exists2 effect: NoExecute3 tolerationSeconds: 60004 resources: limits: memory: 2Gi requests: cpu: 100m memory: 1Gi replicas: 1 # ...
此容忍度与 oc adm taint 命令创建的污点匹配。具有此容限的 pod 可以调度到 node1 上。
12.2.4. 使用容忍度来控制日志收集器 pod 放置 复制链接链接已复制到粘贴板!
默认情况下,日志收集器 pod 具有以下 tolerations 配置:
apiVersion: v1
kind: Pod
metadata:
name: collector-example
namespace: openshift-logging
spec:
# ...
collection:
type: vector
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
- effect: NoSchedule
key: node.kubernetes.io/disk-pressure
operator: Exists
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
- effect: NoSchedule
key: node.kubernetes.io/memory-pressure
operator: Exists
- effect: NoSchedule
key: node.kubernetes.io/pid-pressure
operator: Exists
- effect: NoSchedule
key: node.kubernetes.io/unschedulable
operator: Exists
# ...
先决条件
-
已安装 Red Hat OpenShift Logging Operator 和 OpenShift CLI (
oc)。
流程
运行以下命令,将污点添加到要在其上调度日志记录收集器 pod 的节点:
$ oc adm taint nodes <node_name> <key>=<value>:<effect>示例命令
$ oc adm taint nodes node1 collector=node:NoExecute本例在
node1上放置一个键为collector且值为node的污点,污点效果是NoExecute。您必须使用NoExecute污点设置。NoExecute仅调度与污点匹配的 pod,并删除不匹配的现有 pod。编辑
ClusterLogging自定义资源(CR)的collection小节,以配置日志记录收集器 Pod 的容忍度:apiVersion: logging.openshift.io/v1 kind: ClusterLogging metadata: # ... spec: # ... collection: type: vector tolerations: - key: collector1 operator: Exists2 effect: NoExecute3 tolerationSeconds: 60004 resources: limits: memory: 2Gi requests: cpu: 100m memory: 1Gi # ...
此容忍度与 oc adm taint 命令创建的污点匹配。具有此容忍度的 pod 可以调度到 node1 上。