본문 바로가기
Linux/OpenShift

RHOCP) OpenShift Logging (7) - 클러스터 Event 수집 및 저장

by LILO 2023. 8. 5.
반응형

INTRO

이 글에서는 RHOCP(Redhat Openshift Container Platform) 클러스터에서 발생하는 이벤트를 Kibana에서 볼 수 있게 하기 위해서 Event router를 설정하는 방법을 소개합니다.

Event: Kubernetes 리소스들의 status 변화, 에러 또는 시스템에 특정 messages를 전파해야할 때 사용됨
(https://binux.tistory.com/95)

 

자세한 내용은 아래의 문서를 참고바랍니다.

 

Collecting and storing Kubernetes events | Logging | OpenShift Container Platform 4.13

Use the following steps to deploy the Event Router into your cluster. You should always deploy the Event Router to the openshift-logging project to ensure it collects events from across the cluster. The following Template object creates the service account

docs.openshift.com

 

 

 

Event Router 배포 및 구성

cluster-admin 역할이 있는 사용자로 작업해야되고 Openshift Logging이 설치되어 있어야 합니다.

Event router에 사용될 Template을 생성합니다.

# cat << EOF > event-router.yaml
kind: Template
apiVersion: template.openshift.io/v1
metadata:
  name: eventrouter-template
  annotations:
    description: "A pod forwarding kubernetes events to OpenShift Logging stack."
    tags: "events,EFK,logging,cluster-logging"
objects:
  - kind: ServiceAccount 
    apiVersion: v1
    metadata:
      name: eventrouter
      namespace: ${NAMESPACE}
  - kind: ClusterRole 
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: event-reader
    rules:
    - apiGroups: [""]
      resources: ["events"]
      verbs: ["get", "watch", "list"]
  - kind: ClusterRoleBinding  
    apiVersion: rbac.authorization.k8s.io/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:
                requests:
                  cpu: ${CPU}
                  memory: ${MEMORY}
              volumeMounts:
              - name: config-volume
                mountPath: /etc/eventrouter
          volumes:
            - name: config-volume
              configMap:
                name: eventrouter
parameters:
  - name: IMAGE 
    displayName: Image
    value: "harbor.example.com:443/ocp4/openshift-logging/eventrouter-rhel8:v0.4"
  - name: CPU  
    displayName: CPU
    value: "100m"
  - name: MEMORY 
    displayName: Memory
    value: "128Mi"
  - name: NAMESPACE
    displayName: Namespace
    value: "openshift-logging" 
EOF
- Event router에 사용될 서비스 계정 생성
- get, watch, view 등의 verbs로 이벤트를 감시하는 event-router라는 ClusterRole을 정의 후 바인딩
- config.json 파일을 생성하는 configmap 생성
- Deployments를 이용하여 Event router pod 생성
- value의 원본 이미지인 "https://registry.redhat.io/openshift-logging/eventrouter-rhel8:v0.4"  이미지를 pull해서 Private Reigstry에 push 필요

 

생성한 템플릿을 적용합니다.

oc process -f event-router.yaml | oc apply -n openshift-logging -f -

이벤트가 정상적으로 수집되고 있는지 확인합니다.

# oc get pod -n openshift-logging eventrouter-58c6b5b769-2db7p
NAME                           READY   STATUS    RESTARTS   AGE
eventrouter-58c6b5b769-2db7p   1/1     Running   0          10h


<이벤트 확인>
# oc logs pod/eventrouter-58c6b5b769-2db7p -n openshift-logging |tail |jq .

    "involvedObject": {
      "kind": "PrometheusRule",
      "namespace": "openshift-logging",
      "name": "collector",
      "apiVersion": "monitoring.coreos.com/v1"
    },
    "reason": "GetObject",
    "message": "GetObject PrometheusRule openshift-logging/collector because of change in spec.",
    "source": {
      "component": "clusterlogging-controller"
    },
    "firstTimestamp": "2023-08-03T15:02:48Z",
    "lastTimestamp": "2023-08-05T04:17:48Z",
    "count": 7830,
    "type": "Normal",
    "eventTime": null,
    "reportingComponent": "",
    "reportingInstance": ""
  }
}
반응형