Chapter 4. Install the Red Hat OpenShift Logging Operator
The Red Hat OpenShift Logging Operator deploys and manages the log collector (Vector) that tails container logs and forwards them to a log store. You can install the Red Hat OpenShift Logging Operator by using the OpenShift CLI (oc) or the OpenShift Container Platform web console.
Installing the Red Hat OpenShift Logging Operator deploys the log collector but does not configure log storage or forwarding. After installation, create a LokiStack custom resource to deploy log storage, or configure a ClusterLogForwarder to forward logs to an external system.
4.1. Install the Red Hat OpenShift Logging Operator by using the CLI Copy linkLink copied to clipboard!
Install the Red Hat OpenShift Logging Operator to manage log collection and forwarding by using the OpenShift CLI (oc).
Prerequisites
- You have administrator permissions.
-
You have installed the OpenShift CLI (
oc). -
You have installed and configured the Loki Operator and deployed a
LokiStackinstance. -
You have created the
openshift-loggingnamespace.
Procedure
Create an
OperatorGroupobject:apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: cluster-logging namespace: openshift-logging spec: upgradeStrategy: DefaultApply the
OperatorGroupobject by running the following command:$ oc apply -f <filename>.yamlCreate a
Subscriptionobject for the Red Hat OpenShift Logging Operator:apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name: cluster-logging namespace: openshift-logging spec: channel: stable-6.6 installPlanApproval: Automatic name: cluster-logging source: redhat-operators sourceNamespace: openshift-marketplacespec.channel-
Specify
stable-6.6as the channel. This must match the channel used for the Loki Operator. spec.source-
Specify
redhat-operatorsas the value. If your OpenShift Container Platform cluster is installed on a restricted network, specify the name of theCatalogSourceobject you created when you configured OLM.
Apply the
Subscriptionobject by running the following command:$ oc apply -f <filename>.yamlVerify that the operator installed successfully by running the following command:
$ oc get csv -n openshift-loggingYou get an output similar to the following example:
NAME DISPLAY VERSION PHASE cluster-logging.v6.6.0 Red Hat OpenShift Logging 6.6.0 Succeeded
4.2. Create the collector service account and RBAC Copy linkLink copied to clipboard!
The log collector requires a service account with specific cluster roles to read container logs and write to the LokiStack.
Procedure
Create a service account for the log collector:
$ oc create sa logging-collector -n openshift-loggingAssign the required cluster roles to the service account:
$ oc adm policy add-cluster-role-to-user logging-collector-logs-writer \ -z logging-collector -n openshift-logging$ oc adm policy add-cluster-role-to-user collect-application-logs \ -z logging-collector -n openshift-logging$ oc adm policy add-cluster-role-to-user collect-infrastructure-logs \ -z logging-collector -n openshift-loggingNoteThese three cluster roles are created by the Red Hat OpenShift Logging Operator:
-
logging-collector-logs-writer: Allows writing logs to theLokiStack. -
collect-application-logs: Allows reading application container logs. -
collect-infrastructure-logs: Allows reading infrastructure container logs.
If you also want to collect audit logs, add the
collect-audit-logscluster role.WarningYou must grant the
ClusterRoleBindingsto the service account before adding the corresponding input type to theClusterLogForwardercustom resource (CR). If you add an input type to the CR without the required RBAC binding, the entire log collector DaemonSet is deleted and all log collection fails.-
4.3. Create the ClusterLogForwarder Copy linkLink copied to clipboard!
Create a ClusterLogForwarder CR to define how logs are collected and where they are forwarded.
Procedure
Create a
ClusterLogForwarderCR:apiVersion: observability.openshift.io/v1 kind: ClusterLogForwarder metadata: name: instance namespace: openshift-logging spec: serviceAccount: name: logging-collector outputs: - name: lokistack-out type: lokiStack lokiStack: target: name: logging-loki namespace: openshift-logging authentication: token: from: serviceAccount tls: ca: key: service-ca.crt configMapName: logging-loki-gateway-ca-bundle pipelines: - name: infra-app-logs inputRefs: - application - infrastructure outputRefs: - lokistack-outspec.serviceAccount.name- Specify the service account created in the previous step.
outputs[0].type-
Select the
lokiStackoutput type to send logs to theLokiStackinstance. outputs[0].lokiStack.target.name-
Must match the name of the
LokiStackinstance you created. outputs[0].tls.ca-
Required. The
LokiStackgateway uses the OpenShift service-serving CA for TLS. Without this block, the collector fails withcertificate verify failed: self-signed certificate in certificate chain. pipelines[0].inputRefsSelect the log types to forward. Options:
application,infrastructure, andaudit.ImportantThe
tls.cablock is required when forwarding logs to aLokiStackin the same cluster. TheLokiStackgateway endpoint uses a TLS certificate signed by the cluster’s service-serving CA, which is not in the system truststore. If you omit this block, theClusterLogForwarderstatus might showReady: True, but the collector pods fail to connect at runtime.
Apply the
ClusterLogForwarderCR by running the following command:$ oc apply -f <filename>.yaml
4.4. Install the Red Hat OpenShift Logging Operator by using the web console Copy linkLink copied to clipboard!
Install the Red Hat OpenShift Logging Operator to manage log collection and forwarding from the OperatorHub by using the OpenShift Container Platform web console.
Prerequisites
- You have administrator permissions.
- You have access to the OpenShift Container Platform web console.
-
You installed and configured the Loki Operator and deployed a
LokiStackinstance.
Procedure
-
In the OpenShift Container Platform web console Administrator perspective, go to Operators
OperatorHub. - Type Red Hat OpenShift Logging in the Filter by keyword field. Click Red Hat OpenShift Logging Operator in the list of available Operators, and then click Install.
Select stable-6.6 as the Update channel.
The Red Hat OpenShift Logging Operator must be deployed to the
openshift-loggingnamespace, so the Installation mode and Installed Namespace are already selected. If this namespace does not already exist, it is created for you.Select Enable Operator-recommended cluster monitoring on this namespace.
This option sets the
openshift.io/cluster-monitoring: "true"label in theNamespaceobject. You must select this option to ensure that cluster monitoring scrapes theopenshift-loggingnamespace.For Update approval select Automatic, then click Install.
NoteAn Operator might display a
Failedstatus before the installation completes. If the Operator installation completes with anInstallSucceededmessage, refresh the page.While the Operator installs, create the service account for the log collector:
- Click the + button in the top right of the screen to access the Import YAML page.
Enter the following YAML to create the service account:
apiVersion: v1 kind: ServiceAccount metadata: name: logging-collector namespace: openshift-logging- Click Create.
Create the required cluster role bindings for the log collector. Click the + button again and enter the following YAML:
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: logging-collector:write-logs roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: logging-collector-logs-writer subjects: - kind: ServiceAccount name: logging-collector namespace: openshift-logging --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: logging-collector:collect-application roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: collect-application-logs subjects: - kind: ServiceAccount name: logging-collector namespace: openshift-logging --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: logging-collector:collect-infrastructure roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: collect-infrastructure-logs subjects: - kind: ServiceAccount name: logging-collector namespace: openshift-loggingNoteIf you also want to collect audit logs, add an additional
ClusterRoleBindingwith the cluster rolecollect-audit-logs.- Click Create.
-
Navigate to Operators
Installed Operators. Select the Red Hat OpenShift Logging Operator, and under Provided APIs, find the ClusterLogForwarder resource and click Create Instance. Select YAML view, and then use the following template to create a
ClusterLogForwarderCR:apiVersion: observability.openshift.io/v1 kind: ClusterLogForwarder metadata: name: instance namespace: openshift-logging spec: serviceAccount: name: logging-collector outputs: - name: lokistack-out type: lokiStack lokiStack: target: name: logging-loki namespace: openshift-logging authentication: token: from: serviceAccount tls: ca: key: service-ca.crt configMapName: openshift-service-ca.crt pipelines: - name: infra-app-logs inputRefs: - application - infrastructure outputRefs: - lokistack-outImportantThe
tls.cablock is required. Without it, the collector pods fail to connect to theLokiStackgateway with acertificate verify failederror. TheClusterLogForwarderstatus might showReady: Trueeven when this block is missing.- Click Create.
Verification
-
In the ClusterLogForwarder tab, verify that you see your
ClusterLogForwarderinstance. In the Status column, verify that you see the following conditions:
-
observability.openshift.io/Authorized -
observability.openshift.io/Valid, Ready
-
4.5. Create the log file metric exporter Copy linkLink copied to clipboard!
Create a LogFileMetricExporter custom resource (CR) to generate metrics about the logs produced by running containers. The Operator does not deploy the exporter by default, so you must create it manually.
If you do not create the LogFileMetricExporter CR, the Produced Logs field in the OpenShift Container Platform web console dashboard shows No datapoints found.
Prerequisites
- You have administrator permissions.
- Ensure that you installed the Red Hat OpenShift Logging Operator.
-
You have installed the OpenShift CLI (
oc).
Procedure
Create a
LogFileMetricExporterCR as a YAML file:apiVersion: logging.openshift.io/v1alpha1 kind: LogFileMetricExporter metadata: name: instance namespace: openshift-logging spec: nodeSelector: {} resources: limits: cpu: 500m memory: 256Mi requests: cpu: 200m memory: 128Mi tolerations: []spec.nodeSelector- Optional: Define the nodes that the exporter pods run on.
spec.resources- Optional: Define CPU and memory resource limits and requests for the exporter.
spec.tolerationsOptional: Define tolerations that the exporter pods accept.
NoteThe
LogFileMetricExporteris a singleton. The Operator only honorsopenshift-logging/instancefor the namespace and name.
Run the following command to apply the
LogFileMetricExporterCR:$ oc apply -f <filename>.yaml
Verification
Run the following command to verify that the
logfilesmetricexporterpods are running:$ oc get pods -l app.kubernetes.io/component=logfilesmetricexporter \ -n openshift-loggingExample output
NAME READY STATUS RESTARTS AGE logfilesmetricexporter-9qbjj 1/1 Running 0 2m46s logfilesmetricexporter-cbc4v 1/1 Running 0 2m46sA
logfilesmetricexporterpod runs concurrently with acollectorpod on each node.
4.6. Verify the logging installation Copy linkLink copied to clipboard!
After completing all installation steps, verify that the complete logging pipeline is working.
Procedure
Check that collector pods are running on each node:
$ oc get pods -n openshift-logging -l app.kubernetes.io/component=collectorYou should see one collector pod per node in your cluster.
Check the collector logs for errors:
$ oc logs -n openshift-logging -l app.kubernetes.io/component=collector --tail=20Healthy output has only
WARNmessages about small files. If you seecertificate verify failed, verify thetls.cablock in yourClusterLogForwarder.Query logs from the web console:
Click to Observe
Logs and run the following query: {log_type="infrastructure"}You should see infrastructure log entries from your cluster.