第 5 章 使用事件路由器
事件路由器(Event Router)与 OpenShift Container Platform 通信,并将 OpenShift Container Platform 事件输出到发生事件的 Pod 的日志中。
如果部署了集群日志记录,您可以在 Kibana 中查看 OpenShift Container Platform 事件。
5.1. 部署和配置事件路由器
使用以下步骤将事件路由器部署到集群中。
以下 Template 对象创建事件路由器所需的服务帐户、ClusterRole 和 ClusterRoleBinding。
先决条件
- 需要适当的权限,以便能创建服务帐户和更新集群角色绑定。例如,您可以使用具有 cluster-admin 角色的用户来运行以下模板。
设置
TRANSFORM_EVENTS=true
,以便在 Elasticsearch 中处理和存储事件路由器事件。- 将集群日志记录设置为非受管状态。
启用
TRANSFORM_EVENTS
功能。$ oc set env ds/fluentd TRANSFORM_EVENTS=true
流程
为事件路由器创建模板:
kind: Template apiVersion: v1 metadata: name: eventrouter-template annotations: description: "A pod forwarding kubernetes events to cluster logging stack." tags: "events,EFK,logging,cluster-logging" objects: - kind: ServiceAccount 1 apiVersion: v1 metadata: name: eventrouter namespace: ${NAMESPACE} - kind: ClusterRole 2 apiVersion: v1 metadata: name: event-reader rules: 3 - apiGroups: [""] resources: ["events"] verbs: ["get", "watch", "list"] - kind: ClusterRoleBinding 4 apiVersion: v1 metadata: name: event-reader-binding subjects: - kind: ServiceAccount name: eventrouter namespace: ${NAMESPACE} roleRef: kind: ClusterRole name: event-reader - kind: ConfigMap apiVersion: v1 metadata: name: eventrouter namespace: ${NAMESPACE} data: config.json: |- { "sink": "stdout" } - kind: Deployment apiVersion: apps/v1 metadata: name: eventrouter namespace: ${NAMESPACE} labels: component: eventrouter logging-infra: eventrouter provider: openshift spec: selector: matchLabels: component: eventrouter logging-infra: eventrouter provider: openshift replicas: 1 template: metadata: labels: component: eventrouter logging-infra: eventrouter provider: openshift name: eventrouter spec: serviceAccount: eventrouter containers: - name: kube-eventrouter image: ${IMAGE} imagePullPolicy: IfNotPresent resources: limits: memory: ${MEMORY} requests: cpu: ${CPU} memory: ${MEMORY} volumeMounts: - name: config-volume mountPath: /etc/eventrouter volumes: - name: config-volume configMap: name: eventrouter parameters: - name: IMAGE 5 displayName: Image value: "registry.redhat.io/openshift4/ose-logging-eventrouter:latest" - name: MEMORY 6 displayName: Memory value: "128Mi" - name: CPU 7 displayName: CPU value: "100m" - name: NAMESPACE 8 displayName: Namespace value: "openshift-logging"
- 1
- 为事件路由器创建服务帐户。
- 2
- 创建用于监控集群中事件的集群角色。
- 3
- 授予
events
资源get
、watch
和list
权限。 - 4
- 创建一个 ClusterRoleBinding 将 ClusterRole 绑定到 ServiceAccount。
- 5
- 为事件路由器指定镜像版本。
- 6
- 为事件路由器 Pod 指定内存限值。默认值为“128Mi”。
- 7
- 指定分配给事件路由器的最小 CPU 数量。默认值为“100m”。
- 8
- 指定要部署事件路由器的命名空间。默认值为
openshift-logging
。该值必须与为 ServiceAccount 和 ClusterRoleBinding 指定的值相同。该项目指示您可以在 Kibana 中查找事件的位置:-
如果事件路由器 Pod 部署到默认项目中,如
kube-*
和openshift-*
,您可以在 .operation 索引下查找事件。 - 如果事件路由器 Pod 部署到其他项目中,您可以在使用项目命名空间的索引下查找事件。
-
如果事件路由器 Pod 部署到默认项目中,如
使用以下命令来处理和应用模板:
$ oc process -f <templatefile> | oc apply -f -
例如:
$ oc process -f eventrouter.yaml | oc apply -f - serviceaccount/logging-eventrouter created clusterrole.authorization.openshift.io/event-reader created clusterrolebinding.authorization.openshift.io/event-reader-binding created configmap/logging-eventrouter created deployment.apps/logging-eventrouter created
验证是否安装了事件路由器:
$ oc get pods --selector component=eventrouter -o name pod/logging-eventrouter-d649f97c8-qvv8r
$ oc logs logging-eventrouter-d649f97c8-qvv8r {"verb":"ADDED","event":{"metadata":{"name":"elasticsearch-operator.v0.0.1.158f402e25397146","namespace":"openshift-operators","selfLink":"/api/v1/namespaces/openshift-operators/events/elasticsearch-operator.v0.0.1.158f402e25397146","uid":"37b7ff11-4f1a-11e9-a7ad-0271b2ca69f0","resourceVersion":"523264","creationTimestamp":"2019-03-25T16:22:43Z"},"involvedObject":{"kind":"ClusterServiceVersion","namespace":"openshift-operators","name":"elasticsearch-operator.v0.0.1","uid":"27b2ca6d-4f1a-11e9-8fba-0ea949ad61f6","apiVersion":"operators.coreos.com/v1alpha1","resourceVersion":"523096"},"reason":"InstallSucceeded","message":"waiting for install components to report healthy","source":{"component":"operator-lifecycle-manager"},"firstTimestamp":"2019-03-25T16:22:43Z","lastTimestamp":"2019-03-25T16:22:43Z","count":1,"type":"Normal"}}