From b8f51aa429715dde0d830b78f136c35b96f954b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 3 Nov 2023 09:48:09 +0100 Subject: [PATCH 1/3] Use more tech-agnostic names for the search backend --- README.adoc | 4 +- src/main/kubernetes/openshift.yml | 40 +++++++++---------- src/main/resources/application.properties | 8 ++-- .../mapping-template.json | 0 4 files changed, 26 insertions(+), 26 deletions(-) rename src/main/resources/{elasticsearch => indexes}/mapping-template.json (100%) diff --git a/README.adoc b/README.adoc index 31be5197..b2025f82 100644 --- a/README.adoc +++ b/README.adoc @@ -106,10 +106,10 @@ you will need to set up a few things manually: `search-quarkus-io-secret`:: Secret environment variables for the application. Put in there whatever secret configuration you need for your specific cluster. - `elasticsearch-config`:: + `search-backend-config`:: Environment variables for the Elasticsearch instances. Put in there whatever configuration you need for your specific cluster. - `elasticsearch-secret`:: + `search-backend-secret`:: Secret environment variables for the Elasticsearch instances. Put in there whatever secret configuration you need for your specific cluster. diff --git a/src/main/kubernetes/openshift.yml b/src/main/kubernetes/openshift.yml index a9b70a5b..bbb2c22a 100644 --- a/src/main/kubernetes/openshift.yml +++ b/src/main/kubernetes/openshift.yml @@ -1,10 +1,10 @@ apiVersion: v1 kind: Service metadata: - name: elasticsearch + name: search-backend labels: - app: elasticsearch - app.kubernetes.io/name: elasticsearch + app: search-backend + app.kubernetes.io/name: search-backend app.kubernetes.io/component: datastore app.kubernetes.io/part-of: search-quarkus-io app.kubernetes.io/managed-by: quarkus @@ -17,7 +17,7 @@ spec: protocol: TCP port: 9300 selector: - app.kubernetes.io/name: elasticsearch + app.kubernetes.io/name: search-backend type: ClusterIP # Using a StatefulSet, each pod has its own immutable address, # so we don't need the service to have an IP. @@ -26,31 +26,31 @@ spec: apiVersion: apps/v1 kind: StatefulSet metadata: - name: elasticsearch + name: search-backend labels: - app: elasticsearch - app.kubernetes.io/name: elasticsearch + app: search-backend + app.kubernetes.io/name: search-backend app.kubernetes.io/component: datastore app.kubernetes.io/part-of: search-quarkus-io app.kubernetes.io/managed-by: quarkus # See https://www.hafifbilgiler.com/hafif-bilgiler/elasticsearch-installation-on-openshift/ spec: - serviceName: elasticsearch + serviceName: search-backend replicas: 3 selector: matchLabels: - app.kubernetes.io/name: elasticsearch + app.kubernetes.io/name: search-backend template: metadata: labels: - app: elasticsearch - app.kubernetes.io/name: elasticsearch + app: search-backend + app.kubernetes.io/name: search-backend app.kubernetes.io/component: datastore app.kubernetes.io/part-of: search-quarkus-io app.kubernetes.io/managed-by: quarkus spec: containers: - - name: elasticsearch + - name: search-backend image: elasticsearch:8.10.2 imagePullPolicy: Always resources: @@ -86,9 +86,9 @@ spec: # https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#discovery-settings # Rely on OpenShift's internal DNS to address the other hosts - name: discovery.seed_hosts - value: "elasticsearch-0.elasticsearch,elasticsearch-1.elasticsearch,elasticsearch-2.elasticsearch" + value: "search-backend-0.search-backend,search-backend-1.search-backend,search-backend-2.search-backend" - name: cluster.initial_master_nodes - value: "elasticsearch-0,elasticsearch-1,elasticsearch-2" + value: "search-backend-0,search-backend-1,search-backend-2" # Not exposed to the internet, no sensitive data # => We don't bother with HTTPS and pesky self-signed certificates - name: xpack.security.enabled @@ -100,15 +100,15 @@ spec: value: 127.0.0.1:9200 envFrom: - configMapRef: - name: elasticsearch-config + name: search-backend-config - secretRef: - name: elasticsearch-secrets + name: search-backend-secrets volumeClaimTemplates: - metadata: name: data labels: - app: elasticsearch - app.kubernetes.io/name: elasticsearch + app: search-backend + app.kubernetes.io/name: search-backend app.kubernetes.io/component: datastore app.kubernetes.io/part-of: search-quarkus-io app.kubernetes.io/managed-by: quarkus @@ -124,7 +124,7 @@ spec: imageChangeParams: automatic: true containerNames: - - elasticsearch + - search-backend from: kind: ImageStreamTag name: elasticsearch:8.10.2 @@ -134,7 +134,7 @@ kind: "ImageStream" metadata: name: elasticsearch labels: - app.kubernetes.io/name: elasticsearch + app.kubernetes.io/name: search-backend app.kubernetes.io/component: datastore app.kubernetes.io/part-of: search-quarkus-io app.kubernetes.io/managed-by: quarkus diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f571b122..e3a01b23 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,7 +23,7 @@ quarkus.hibernate-orm.database.generation=drop-and-create quarkus.hibernate-search-orm.elasticsearch.version=8.10 quarkus.elasticsearch.devservices.image-name=docker.io/elastic/elasticsearch:8.10.2 ## We need to apply a custom Elasticsearch mapping to exclude very large fields from the _source -quarkus.hibernate-search-orm.elasticsearch.schema-management.mapping-file=elasticsearch/mapping-template.json +quarkus.hibernate-search-orm.elasticsearch.schema-management.mapping-file=indexes/mapping-template.json ## We don't expect Elasticsearch to be reachable when the application starts quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=false ## ... and the application automatically creates indexes upon first indexing anyway. @@ -68,9 +68,9 @@ quarkus.swagger-ui.title=Quarkus Search API # Deployment to OpenShift quarkus.container-image.builder=openshift quarkus.openshift.part-of=search-quarkus-io -# See src/main/kubernetes/openshift.yml for the Elasticsearch StatefulSet definition -# Rely on OpenShift's internal DNS to resolve the IP to Elasticsearch nodes -quarkus.openshift.env.vars.quarkus-hibernate-search-orm-elasticsearch-hosts=elasticsearch-0.elasticsearch:9200,elasticsearch-1.elasticsearch:9200,elasticsearch-2.elasticsearch:9200 +# See src/main/kubernetes/openshift.yml for the search-backend StatefulSet definition +# Rely on OpenShift's internal DNS to resolve the IP to search-backend nodes +quarkus.openshift.env.vars.quarkus-hibernate-search-orm-elasticsearch-hosts=search-backend-0.search-backend:9200,search-backend-1.search-backend:9200,search-backend-2.search-backend:9200 # Images built on OpenShift have their HOME environment variable set to '/' by default, # which obviously won't work well due to filesystem permissions. # JGit in particular doesn't like it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=560555 diff --git a/src/main/resources/elasticsearch/mapping-template.json b/src/main/resources/indexes/mapping-template.json similarity index 100% rename from src/main/resources/elasticsearch/mapping-template.json rename to src/main/resources/indexes/mapping-template.json From 2c531810be80c1bd50c45509cca2d75a38550d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 3 Nov 2023 10:00:07 +0100 Subject: [PATCH 2/3] Enable memory lock for Elasticsearch --- src/main/kubernetes/openshift.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kubernetes/openshift.yml b/src/main/kubernetes/openshift.yml index bbb2c22a..418fc256 100644 --- a/src/main/kubernetes/openshift.yml +++ b/src/main/kubernetes/openshift.yml @@ -94,7 +94,7 @@ spec: - name: xpack.security.enabled value: "false" - name: bootstrap.memory_lock - value: "false" + value: "true" # https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_configure_and_start_the_cluster - name: ES_PORT value: 127.0.0.1:9200 From e4dcd09619ae93a4ca2e272990f0190097d4277c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 3 Nov 2023 10:00:36 +0100 Subject: [PATCH 3/3] Migrate to OpenSearch --- README.adoc | 6 +++--- src/main/kubernetes/openshift.yml | 23 ++++++++++------------- src/main/resources/application.properties | 8 ++++---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/README.adoc b/README.adoc index b2025f82..b56380bf 100644 --- a/README.adoc +++ b/README.adoc @@ -64,7 +64,7 @@ podman pod create -p 8080:8080 -p 9000:9000 -p 9200:9200 --name search.quarkus.i podman container run -d --name elasticearch --pod search.quarkus.io \ -e "discovery.type=single-node" -e "xpack.security.enabled=false" \ -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" -e "cluster.routing.allocation.disk.threshold_enabled=false" \ - elastic/elasticsearch:8.10.2 + docker.io/opensearchproject/opensearch:2.11.0 # Then the app; this will fetch the actual data on startup (might take a while): podman container run -it --rm --pod search.quarkus.io search-quarkus-io:999-SNAPSHOT # OR, if you already have a local clone of quarkus.io: @@ -107,10 +107,10 @@ you will need to set up a few things manually: Secret environment variables for the application. Put in there whatever secret configuration you need for your specific cluster. `search-backend-config`:: - Environment variables for the Elasticsearch instances. + Environment variables for the OpenSearch instances. Put in there whatever configuration you need for your specific cluster. `search-backend-secret`:: - Secret environment variables for the Elasticsearch instances. + Secret environment variables for the OpenSearch instances. Put in there whatever secret configuration you need for your specific cluster. [[license]] diff --git a/src/main/kubernetes/openshift.yml b/src/main/kubernetes/openshift.yml index 418fc256..7907f468 100644 --- a/src/main/kubernetes/openshift.yml +++ b/src/main/kubernetes/openshift.yml @@ -51,7 +51,7 @@ spec: spec: containers: - name: search-backend - image: elasticsearch:8.10.2 + image: opensearch:2.11.0 imagePullPolicy: Always resources: limits: @@ -75,7 +75,7 @@ spec: protocol: TCP volumeMounts: - name: data - mountPath: /usr/share/elasticsearch/data + mountPath: /usr/share/opensearch/data env: - name: cluster.name value: search-quarkus-io @@ -83,21 +83,18 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name - # https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#discovery-settings + # https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/#sample-docker-composeyml # Rely on OpenShift's internal DNS to address the other hosts - name: discovery.seed_hosts value: "search-backend-0.search-backend,search-backend-1.search-backend,search-backend-2.search-backend" - - name: cluster.initial_master_nodes + - name: cluster.initial_cluster_manager_nodes value: "search-backend-0,search-backend-1,search-backend-2" # Not exposed to the internet, no sensitive data # => We don't bother with HTTPS and pesky self-signed certificates - - name: xpack.security.enabled - value: "false" + - name: plugins.security.disabled + value: "true" - name: bootstrap.memory_lock value: "true" - # https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_configure_and_start_the_cluster - - name: ES_PORT - value: 127.0.0.1:9200 envFrom: - configMapRef: name: search-backend-config @@ -127,12 +124,12 @@ spec: - search-backend from: kind: ImageStreamTag - name: elasticsearch:8.10.2 + name: opensearch:2.11.0 --- apiVersion: "v1" kind: "ImageStream" metadata: - name: elasticsearch + name: opensearch labels: app.kubernetes.io/name: search-backend app.kubernetes.io/component: datastore @@ -140,7 +137,7 @@ metadata: app.kubernetes.io/managed-by: quarkus spec: tags: - - name: 8.10.2 + - name: 2.11.0 from: kind: DockerImage - name: docker.elastic.co/elasticsearch/elasticsearch:8.10.2 \ No newline at end of file + name: docker.io/opensearchproject/opensearch:2.11.0 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e3a01b23..8bb6fd5e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,11 +20,11 @@ quarkus.http.header."Strict-Transport-Security".value=max-age=31536000; includeS quarkus.datasource.jdbc.url=jdbc:h2:mem:searchquarkusio quarkus.hibernate-orm.database.generation=drop-and-create ## Hibernate Search -quarkus.hibernate-search-orm.elasticsearch.version=8.10 -quarkus.elasticsearch.devservices.image-name=docker.io/elastic/elasticsearch:8.10.2 -## We need to apply a custom Elasticsearch mapping to exclude very large fields from the _source +quarkus.hibernate-search-orm.elasticsearch.version=opensearch:2.11 +quarkus.elasticsearch.devservices.image-name=docker.io/opensearchproject/opensearch:2.11.0 +## We need to apply a custom OpenSearch mapping to exclude very large fields from the _source quarkus.hibernate-search-orm.elasticsearch.schema-management.mapping-file=indexes/mapping-template.json -## We don't expect Elasticsearch to be reachable when the application starts +## We don't expect OpenSearch to be reachable when the application starts quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=false ## ... and the application automatically creates indexes upon first indexing anyway. quarkus.hibernate-search-orm.schema-management.strategy=none