-
Create an AWS S3 bucket or other storage object
Command to create a bucket named my-bucket-logging-loki in region us-east-1aws s3api create-bucket --acl private --region us-east-1 --bucket my-bucket-logging-lokiAddtional option required for any region other than us-east-1--create-bucket-configuration LocationConstraint="$REGION"
NoteBucket names must be unique and should be prepended with an easily identifiable term (i.e. username or cluster_id) - Access Control
-
AWS recommends that you turn on all options to block public access for buckets
Block configurations recommendedBlockPublicAcls=true IgnorePublicAcls=true BlockPublicPolicy=true RestrictPublicBuckets=true
-
Create a secret for the lokistack instance (docs)
Secret named logging-loki-s3oc create -n openshift-logging secret generic logging-loki-s3 \ --from-literal=region="us-east-1" \ --from-literal=bucketnames="my-bucket-logging-loki" \ --from-literal=access_key_id="AKIAIOSFODNN7EXAMPLE" \ --from-literal=access_key_secret="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \ --from-literal=endpoint="https://s3.us-east-1.amazonaws.com"or
apiVersion: v1 kind: Secret metadata: name: logging-loki-s3 namespace: openshift-logging stringData: access_key_id: AKIAIOSFODNN7EXAMPLE access_key_secret: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY bucketnames: my-bucket-logging-loki endpoint: https://s3.us-east-1.amazonaws.com region: us-east-1
-
Create an instance of lokistack
LokiStackapiVersion: loki.grafana.com/v1 kind: LokiStack metadata: name: logging-loki namespace: openshift-logging # (1) spec: size: 1x.extra-small # (2) storage: schemas: - version: v13 effectiveDate: 2024-10-23 secret: name: logging-loki-s3 type: s3 storageClassName: gp3-csi tenants: mode: openshift-logging # (3)
-
lokiStack should be created in
openshift-loggingnamespace -
deployment sizes are
1x.demo,1x.extra-small,1x.small,1x.medium -
mode must be
openshift-logging
-
-
Verify the loki pods are all running as expected (requires a few minutes):
Get pods by instance name labeloc get pods -n openshift-logging -l app.kubernetes.io/instance=logging-lokiPods all in Running status$ oc get pods -n openshift-logging -l app.kubernetes.io/instance=logging-loki NAME READY STATUS RESTARTS AGE logging-loki-compactor-0 1/1 Running 0 3m12s logging-loki-distributor-76d55f48df-cmccq 1/1 Running 0 3m13s logging-loki-distributor-76d55f48df-f6ntn 1/1 Running 0 3m13s logging-loki-gateway-7c97698c8-lvc7f 2/2 Running 0 3m12s logging-loki-gateway-7c97698c8-mtb7r 2/2 Running 0 3m12s logging-loki-index-gateway-0 1/1 Running 0 3m12s logging-loki-index-gateway-1 1/1 Running 0 2m44s logging-loki-ingester-0 1/1 Running 0 3m12s logging-loki-ingester-1 1/1 Running 0 117s logging-loki-querier-69c4d55f98-x5llq 1/1 Running 0 3m12s logging-loki-querier-69c4d55f98-xm25s 1/1 Running 0 3m12s logging-loki-query-frontend-77f5964c66-hx8mr 1/1 Running 0 3m12s logging-loki-query-frontend-77f5964c66-phgf6 1/1 Running 0 3m12s
-
Install the Cluster Observability Operator according to the docs
-
Create an instance of the UIPlugin with name logging and type Logging (case sensitive)
UIPlugin for our named lokiStack instanceapiVersion: observability.openshift.io/v1alpha1 kind: UIPlugin metadata: name: logging # (1) spec: type: Logging # (2) logging: lokiStack: name: logging-loki # (3)
-
namemust be logging -
typemust be Logging -
namemust match the name of your lokiStack instance (and must be in openshift-logging namespace)NoteThis will refresh your openshift console and allow you to navigate to the Observe → Logs panel where you can run LogQL queries. Logs for individual pods can also be queried directly from the pods view Aggregated Logs tab More information on UI plugin can be found via the observability operator, or by using
oc explaincommandExample explain commandoc explain uiplugin.spec.loggingView PermissionsThe UIPlugin instance creates three view roles (one for each log type)
cluster-logging-application-view cluster-logging-infrastructure-view cluster-logging-audit-view
ClusterRoleBindings can be used to customize user access to log viewing. More details can be found in the fine-grained access docs.
-
-
Install Red Hat Openshift Logging Operator (version 6.0) from the OperatorHub
-
Create a Service Account to be used by the ClusterLogForwarder
ServiceAccount named logging-adminoc create -n openshift-logging sa logging-admin
-
Create collect and write permissions for the service account by creating a ClusterRoleBinding for each role that is required for your configuration.
ClusterRoleBinding commandoc adm policy add-cluster-role-to-user <cluster_role> -z logging-admincollect cluster rolescollect-application-logs collect-infrastructure-logs collect-audit-logs
NoteThe -zflag used above creates a cluster role binding to the service account in the current namespace. For the logging-admin service account these commands must be run in the openshift-logging namespacewrite cluster roles (forwarding to LokiStack)cluster-logging-write-application-logs cluster-logging-write-infrastructure-logs cluster-logging-write-audit-logs
NoteUse oc create clusterolebinding -hfor more explicit options when creating bindingsRole permissions can be viewed using
oc describe clusterrolecommandExample command$ oc describe clusterrole cluster-logging-write-application-logs Name: cluster-logging-write-application-logs Labels: olm.owner=cluster-logging.v6.0.0 Annotations: <none> PolicyRule: Resources Non-Resource URLs Resource Names Verbs --------- ----------------- -------------- ----- application.loki.grafana.com [] [logs] [create]
-
Create a ClusterLogForwarder instance with output type lokiStack
ClusterLogForwarderapiVersion: observability.openshift.io/v1 kind: ClusterLogForwarder metadata: name: my-forwarder namespace: openshift-logging spec: serviceAccount: name: logging-admin # (1) outputs: - name: default-lokistack type: lokiStack lokiStack: target: name: logging-loki # (2) namespace: openshift-logging authentication: token: from: serviceAccount tls: ca: key: service-ca.crt # (3) configMapName: openshift-service-ca.crt filters: - name: my-multi type: detectMultilineException - name: my-parse type: parse - name: my-labels type: openshiftLabels openshiftLabels: foo: bar pipelines: - name: my-pipeline outputRefs: - default-lokistack inputRefs: - application - infrastructure filterRefs: - my-multi - my-parse - my-labels
-
serviceAccount.namemust have permissions to both collect AND write app and infra logs -
lokiStack.targetname and namespace must match your loki instance name -
TLS configuration
keyandconfigMapNameuses the existing openshift service config map
-
-
Create a ClusterLogForwarder CR to forward logs to individual tenant endpoints in LokiStack
ClusterLogForwarder with custom pipelines, filtered and based on log_typeapiVersion: observability.openshift.io/v1 kind: ClusterLogForwarder metadata: name: my-forwarder namespace: openshift-logging spec: serviceAccount: name: logging-admin outputs: - name: loki-app type: loki loki: url: https://logging-loki-gateway-http.openshift-logging.svc:8080/api/logs/v1/application authentication: token: from: serviceAccount tls: ca: key: service-ca.crt configMapName: openshift-service-ca.crt - name: loki-infra type: loki loki: url: https://logging-loki-gateway-http.openshift-logging.svc:8080/api/logs/v1/infrastructure authentication: token: from: serviceAccount tls: ca: key: service-ca.crt configMapName: openshift-service-ca.crt - name: loki-audit type: loki loki: url: https://logging-loki-gateway-http.openshift-logging.svc:8080/api/logs/v1/audit authentication: token: from: serviceAccount tls: ca: key: service-ca.crt configMapName: openshift-service-ca.crt filters: - name: my-multi type: detectMultilineException - name: my-parse type: parse - name: my-labels type: openshiftLabels openshiftLabels: foo: bar pipelines: - name: send-app-logs inputRefs: - application outputRefs: - loki-app filterRefs: - my-multi - my-parse - my-labels - name: send-infra-logs inputRefs: - infrastructure outputRefs: - loki-infra filterRefs: - my-multi - my-parse - my-labels - name: send-audit-logs inputRefs: - audit outputRefs: - loki-audit filterRefs: - my-multi - my-parse - my-labels
For the internal loki gateway service, we use the url format <service_name>.<namespace>.svc:8080/api/logs/v1/<log_type>
-
The command
logclican be used to query lokistack (docs)Save the route created by our lokiStack named logging-lokiexport LOKI_ROUTE=$(oc get routes logging-loki -o jsonpath="{.spec.host}")Extract the certificate file created by our lokiStack (logging-loki-ca-bundle)oc extract cm/logging-loki-ca-bundle --keys=service-ca.crt --confirmUse logcli to query the infrastructure endpointlogcli --tls-skip-verify --ca-cert=service-ca.crt --bearer-token="$(oc whoami -t)" --addr https://$LOKI_ROUTE/api/logs/v1/infrastructure query '{log_type=~".+a.+"}'NoteUse logcli helpandlogcli query helpto see all options for interacting with loki
- Loki Operator user-guide
-
https://github.com/grafana/loki/blob/main/operator/docs/user-guides/forwarding_logs_to_gateway.md
- Loki Operator object-storage
-
https://github.com/grafana/loki/blob/main/operator/docs/lokistack/object_storage.md
- Observability Operator plugin