|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | + |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="logging-elastic-to-loki-migration_{context}"] |
| 7 | += Migrating the Default Log Store from Elasticsearch to Loki in OpenShift |
| 8 | + |
| 9 | +This guide describes how to switch the OpenShift Logging storage service from Elasticsearch to LokiStack. It focuses on log forwarding, not data migration. After following these steps, old logs will remain in Elasticsearch (accessible via Kibana), while new logs will go to LokiStack (visible in the OpenShift Console). |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* Red Hat OpenShift Logging Operator (v5.5.5+) |
| 14 | +* OpenShift Elasticsearch Operator (v5.5.5+) |
| 15 | +* Red Hat Loki Operator (v5.5.5+) |
| 16 | +* Sufficient resources on target nodes to run both Elasticsearch and LokiStack (see LokiStack Deployment Sizing Table in the documentation). |
| 17 | +
|
| 18 | +== Installing LokiStack |
| 19 | + |
| 20 | +. **Install the Loki Operator:** Follow the official guide to install the Loki Operator using the OpenShift web console. |
| 21 | +.. **Create a Secret for Loki Object Storage:** Create a secret for Loki object storage (e.g., AWS S3). Refer to the documentation for other object storage types. |
| 22 | + |
| 23 | +[source,bash] |
| 24 | +---- |
| 25 | +$ cat << EOF |oc create -f - |
| 26 | +apiVersion: v1 |
| 27 | +kind: Secret |
| 28 | +metadata: |
| 29 | + name: logging-loki-s3 |
| 30 | + namespace: openshift-logging |
| 31 | +data: |
| 32 | + access_key_id: $(echo "PUT_S3_ACCESS_KEY_ID_HERE" | base64 -w0) |
| 33 | + access_key_secret: $(echo "PUT_S3_ACCESS_KEY_SECRET_HERE" | base64 -w0) |
| 34 | + bucketnames: $(echo "s3-bucket-name" | base64 -w0) |
| 35 | + endpoint: $(echo "https://s3.eu-central-1.amazonaws.com" | base64 -w0) |
| 36 | + region: $(echo "eu-central-1" | base64 -w0) |
| 37 | +EOF |
| 38 | +---- |
| 39 | + |
| 40 | + |
| 41 | +... **Deploy LokiStack Custom Resource (CR):** |
| 42 | + |
| 43 | +[NOTE] |
| 44 | +==== |
| 45 | +Change the `spec.size` if needed. |
| 46 | +==== |
| 47 | + |
| 48 | +[source,bash] |
| 49 | +---- |
| 50 | +$ cat << EOF |oc create -f - |
| 51 | +apiVersion: loki.grafana.com/v1 |
| 52 | +kind: LokiStack |
| 53 | +metadata: |
| 54 | + name: logging-loki |
| 55 | + namespace: openshift-logging |
| 56 | +spec: |
| 57 | + size: 1x.small |
| 58 | + storage: |
| 59 | + schemas: |
| 60 | + - version: v12 |
| 61 | + effectiveDate: '2022-06-01' |
| 62 | + secret: |
| 63 | + name: logging-loki-s3 |
| 64 | + type: s3 |
| 65 | + storageClassName: gp2 |
| 66 | + tenants: |
| 67 | + mode: openshift-logging |
| 68 | +EOF |
| 69 | +---- |
| 70 | + |
| 71 | +== Disconnecting Elasticsearch and Kibana |
| 72 | + |
| 73 | +To keep Elasticsearch and Kibana running while transitioning: |
| 74 | + |
| 75 | +. **Set `ClusterLogging` to Unmanaged:** |
| 76 | + |
| 77 | +[source,bash] |
| 78 | +---- |
| 79 | +oc -n openshift-logging patch clusterlogging/instance -p '{"spec":{"managementState": "Unmanaged"}}' --type=merge |
| 80 | +---- |
| 81 | + |
| 82 | +.. **Remove Owner References:** Remove `ClusterLogging` owner references from Elasticsearch and Kibana resources: |
| 83 | + |
| 84 | +[source,bash] |
| 85 | +---- |
| 86 | +$ oc -n openshift-logging patch elasticsearch/elasticsearch -p '{"metadata":{"ownerReferences": []}}' --type=merge |
| 87 | +---- |
| 88 | + |
| 89 | +[source,bash] |
| 90 | +---- |
| 91 | +$ oc -n openshift-logging patch kibana/kibana -p '{"metadata":{"ownerReferences": []}}' --type=merge |
| 92 | +---- |
| 93 | + |
| 94 | +... **Back Up Elasticsearch and Kibana Resources:** Use `yq` to back up these resources to prevent accidental deletion: link:https://github.com/mikefarah/yq[yq utility] |
| 95 | + |
| 96 | +For Elasticsearch: |
| 97 | + |
| 98 | +[source,bash] |
| 99 | +---- |
| 100 | +$ oc -n openshift-logging get elasticsearch elasticsearch -o yaml \ |
| 101 | + | yq 'del(.metadata.resourceVersion) | del(.metadata.uid)' \ |
| 102 | + | yq 'del(.metadata.generation) | del(.metadata.creationTimestamp)' \ |
| 103 | + | yq 'del(.metadata.selfLink) | del(.status)' > /tmp/cr-elasticsearch.yaml |
| 104 | +---- |
| 105 | + |
| 106 | +For Kibana: |
| 107 | + |
| 108 | +[source,bash] |
| 109 | +---- |
| 110 | +$ oc -n openshift-logging get kibana kibana -o yaml \ |
| 111 | + | yq 'del(.metadata.resourceVersion) | del(.metadata.uid)' \ |
| 112 | + | yq 'del(.metadata.generation) | del(.metadata.creationTimestamp)' \ |
| 113 | + | yq 'del(.metadata.selfLink) | del(.status)' > /tmp/cr-kibana.yaml |
| 114 | +---- |
| 115 | + |
| 116 | +== Switching to LokiStack |
| 117 | + |
| 118 | +. Switch Log Storage to LokiStack |
| 119 | +The following manifest will apply several changes to the `ClusterLogging` resource: |
| 120 | +* Re-instate the management state to `Managed`. |
| 121 | +* Switch the `logStore` spec from `elasticsearch` to `lokistack`, restarting the collector pods to start forwarding logs to `lokistack`. |
| 122 | +* Remove the `visualization` spec, prompting the cluster-logging-operator to install the `logging-view-plugin` for observing `lokistack` logs in the OpenShift Console. |
| 123 | +* If the collection type is not `fluentd`, replace it with `vector`. |
| 124 | + |
| 125 | +[source,yaml] |
| 126 | +---- |
| 127 | +$ cat << EOF |oc replace -f - |
| 128 | +apiVersion: logging.openshift.io/v1 |
| 129 | +kind: ClusterLogging |
| 130 | +metadata: |
| 131 | + name: instance |
| 132 | + namespace: openshift-logging |
| 133 | +spec: |
| 134 | + managementState: Managed |
| 135 | + logStore: |
| 136 | + type: lokistack |
| 137 | + lokistack: |
| 138 | + name: logging-loki |
| 139 | + collection: |
| 140 | + logs: |
| 141 | + type: fluentd |
| 142 | + fluentd: {} |
| 143 | + visualization: |
| 144 | + type: kibana |
| 145 | + kibana: |
| 146 | + replicas: 1 |
| 147 | +EOF |
| 148 | +---- |
| 149 | + |
| 150 | +. Re-instantiate Kibana Resource |
| 151 | + |
| 152 | +In the previous step, removing the `visualization` field prompted the operator to remove the `Kibana` resource. Re-instantiate the `Kibana` resource using the backup created earlier. |
| 153 | + |
| 154 | +[source,bash] |
| 155 | +---- |
| 156 | +$ oc -n openshift-logging apply -f /tmp/cr-kibana.yaml |
| 157 | +---- |
| 158 | + |
| 159 | +. Enable the Console View Plugin |
| 160 | + |
| 161 | +Enable the console view plugin to view the logs integrated from the OpenShift Console (Observe > Logs). |
| 162 | + |
| 163 | +[source,bash] |
| 164 | +---- |
| 165 | +$ oc patch consoles.operator.openshift.io cluster --type=merge --patch '{ "spec": { "plugins": ["logging-view-plugin"] } }' |
| 166 | +---- |
| 167 | + |
| 168 | +== Delete the Elasticsearch Stack |
| 169 | + |
| 170 | +Once the retention period for logs stored in Elasticsearch expires and no more logs are visible in Kibana, remove the old stack to release resources. |
| 171 | + |
| 172 | +=== Step 1: Delete Elasticsearch and Kibana Resources |
| 173 | + |
| 174 | +[source,bash] |
| 175 | +---- |
| 176 | +$ oc -n openshift-logging delete kibana/kibana elasticsearch/elasticsearch |
| 177 | +---- |
| 178 | + |
| 179 | +=== |
| 180 | + |
| 181 | + Step 2: Delete the PVCs Used by Elasticsearch Instances |
| 182 | + |
| 183 | +[source,bash] |
| 184 | +---- |
| 185 | +$ oc delete -n openshift-logging pvc -l logging-cluster=elasticsearch |
| 186 | +---- |
0 commit comments