From eec86216f257f6f2d36de8c30e852ac0af987dad Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Fri, 27 Nov 2026 09:28:57 +0000 Subject: [PATCH 1/3] feat(hapi-fhir): add HAPI FHIR chart with plain, untemplated manifests HAPI FHIR JPA server (R4) with PostgreSQL as the store and a single-node Elasticsearch as the full-text index for _text and _content. The chart's templates are plain Kubernetes YAML with no Helm template expressions and no values. Helm packages, versions, installs and removes it; the manifests are applied as written. The hapi-fhir-db Secret is created outside the chart, so CI lints the chart and skips the chart-testing install. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/build_helm_charts.yml | 5 +- .release-please-manifest.json | 1 + deployment/charts/README.md | 10 + deployment/charts/hapi-fhir/Chart.yaml | 14 ++ deployment/charts/hapi-fhir/README.md | 90 +++++++++ .../hapi-fhir/templates/elasticsearch.yaml | 96 +++++++++ .../charts/hapi-fhir/templates/hapi-fhir.yaml | 182 ++++++++++++++++++ .../charts/hapi-fhir/templates/postgres.yaml | 90 +++++++++ deployment/charts/hapi-fhir/values.yaml | 3 + release-please-config.json | 17 ++ 10 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 deployment/charts/hapi-fhir/Chart.yaml create mode 100644 deployment/charts/hapi-fhir/README.md create mode 100644 deployment/charts/hapi-fhir/templates/elasticsearch.yaml create mode 100644 deployment/charts/hapi-fhir/templates/hapi-fhir.yaml create mode 100644 deployment/charts/hapi-fhir/templates/postgres.yaml create mode 100644 deployment/charts/hapi-fhir/values.yaml diff --git a/.github/workflows/build_helm_charts.yml b/.github/workflows/build_helm_charts.yml index f165e5e5..a08e29b1 100644 --- a/.github/workflows/build_helm_charts.yml +++ b/.github/workflows/build_helm_charts.yml @@ -103,7 +103,10 @@ jobs: - name: Run chart-testing (install) if: steps.list-changed.outputs.changed == 'true' working-directory: . - run: ct install --config .github/linters/ct.yaml + # hapi-fhir is linted but not installed: it has no templating, so it cannot be + # scaled to zero for CI, and its pods need the hapi-fhir-db Secret, which is + # created outside the chart. + run: ct install --config .github/linters/ct.yaml --excluded-charts hapi-fhir helm-publish: runs-on: ubuntu-latest diff --git a/.release-please-manifest.json b/.release-please-manifest.json index f2d49cd6..34ff7e0d 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -8,6 +8,7 @@ "deployment/charts/ocr-service": "0.1.0", "deployment/charts/nifi": "0.0.0", "deployment/charts/nginx": "0.0.0", + "deployment/charts/hapi-fhir": "0.0.0", "deployment/terraform/openstack-kubernetes-k3s": "0.1.4", "apps/ocr-service": "1.1.4", "apps/jupyter-hub": "2.3.12" diff --git a/deployment/charts/README.md b/deployment/charts/README.md index fe1bc74e..57794a24 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -43,6 +43,13 @@ Existing deployments must reload `nifi-auth` for NGINX before upgrading. OpenSearch upgrades also require the bootstrap Secret and preparation of administrative access when using an admin certificate. [OpenSearch upgrade details](opensearch/README.md#install) +## HAPI FHIR + +`hapi-fhir/` runs a HAPI FHIR JPA server (R4) with PostgreSQL and a single-node +Elasticsearch for full-text search. Its manifests are plain Kubernetes YAML with +no Helm templating and no values. It needs the `hapi-fhir-db` Secret before +installation. [HAPI FHIR chart](hapi-fhir/README.md) + ## Chart development ```bash @@ -71,6 +78,9 @@ can validate Kubernetes resource installation without deployment-owned ConfigMaps and Secrets. Application startup and TLS checks require a separate runtime test with those inputs supplied. +The HAPI FHIR chart has no values, so it cannot be scaled to zero. CI lints it +and skips the install test, because its pods need the `hapi-fhir-db` Secret. + To package locally, keep generated archives outside the source tree: ```bash diff --git a/deployment/charts/hapi-fhir/Chart.yaml b/deployment/charts/hapi-fhir/Chart.yaml new file mode 100644 index 00000000..5190db50 --- /dev/null +++ b/deployment/charts/hapi-fhir/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: hapi-fhir +description: HAPI FHIR JPA server (R4) with PostgreSQL and Elasticsearch full-text search +type: application +version: 0.1.0 +appVersion: "v8.12.0-2" + +home: https://docs.cogstack.org/ +sources: + - https://github.com/CogStack/cogstack-platform + - https://github.com/hapifhir/hapi-fhir-jpaserver-starter +maintainers: + - name: mooperd +icon: "https://avatars.githubusercontent.com/u/28688163" diff --git a/deployment/charts/hapi-fhir/README.md b/deployment/charts/hapi-fhir/README.md new file mode 100644 index 00000000..3544a4d0 --- /dev/null +++ b/deployment/charts/hapi-fhir/README.md @@ -0,0 +1,90 @@ +# CogStack HAPI FHIR Helm chart + +A [HAPI FHIR](https://hapifhir.io/) JPA server (FHIR R4) with PostgreSQL as the +resource store and a single-node Elasticsearch as its full-text index, which is +what answers `_text` and `_content` searches. Every other search stays in +PostgreSQL, so a search straight after a write still sees it. + +| Workload | Image | Service | Storage | +| --- | --- | --- | --- | +| `hapi-fhir` | `hapiproject/hapi:v8.12.0-2` | `hapi-fhir:8080` | none | +| `hapi-fhir-db` | `postgres:16-alpine` | `hapi-fhir-db:5432` | 10Gi PVC | +| `hapi-fhir-es` | `docker.elastic.co/elasticsearch/elasticsearch:8.19.19` | `hapi-fhir-es:9200` | 10Gi PVC | + +## No templating + +The files in `templates/` are plain Kubernetes YAML. They contain no Helm +template expressions, and the chart has no values: `helm template` prints them +as they are written. Helm packages, versions, installs and removes the chart, +and nothing else. + +This has three consequences. + +- **Fixed names.** Resource names do not include the release name, so install + one release per namespace. +- **No `--set`.** To change an image, a size or a setting, edit the manifests + (or post-process them with `helm template | kustomize`). +- **No automatic restart on a configuration change.** HAPI reads the + `hapi-fhir-config` ConfigMap only at startup. After an upgrade that changes + it, run `kubectl rollout restart deployment/hapi-fhir`. + +## Install + +The chart does not contain the database password. Create the `hapi-fhir-db` +Secret first, in the namespace you install into. Keep it across upgrades: +PostgreSQL sets the password only when it first initialises its volume. + +```bash +kubectl create namespace cogstack +kubectl -n cogstack create secret generic hapi-fhir-db \ + --from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 24)" +helm upgrade --install hapi-fhir deployment/charts/hapi-fhir -n cogstack \ + --wait --timeout 15m +``` + +HAPI waits for PostgreSQL and Elasticsearch, then migrates its schema. The +first start takes a few minutes. + +## Access + +The chart creates only ClusterIP Services. It has no Ingress or HTTPRoute, +because a hostname cannot be set without templating. PostgreSQL and +Elasticsearch are meant to stay inside the cluster; Elasticsearch runs without +authentication. + +```bash +kubectl -n cogstack port-forward svc/hapi-fhir 8080:8080 +curl http://localhost:8080/fhir/metadata +curl 'http://localhost:8080/fhir/Patient?_text=x&_summary=count' +``` + +The second request answers `400` (`HAPI-1192`) if HAPI is not using +Elasticsearch. + +To publish the server, route your own Ingress or Gateway API HTTPRoute to the +`hapi-fhir` Service on port `8080`. HAPI builds its links from the +`X-Forwarded-*` headers the proxy sends. + +If resources were stored before Elasticsearch was attached, index them once: + +```bash +curl -X POST 'http://localhost:8080/fhir/$reindex' \ + -H 'Content-Type: application/fhir+json' \ + -d '{"resourceType":"Parameters"}' +``` + +## Sizing + +Elasticsearch runs with a 512 MB heap and a 1200Mi memory limit, and uses +`node.store.allow_mmap=false` so the nodes need no `vm.max_map_count` change. +PostgreSQL is tuned for about 2 GB of memory. These suit a small shared +cluster; edit the manifests for anything larger. + +## Remove + +```bash +helm uninstall hapi-fhir -n cogstack +``` + +This deletes the PersistentVolumeClaims, and with them the data. The +`hapi-fhir-db` Secret is yours to delete. diff --git a/deployment/charts/hapi-fhir/templates/elasticsearch.yaml b/deployment/charts/hapi-fhir/templates/elasticsearch.yaml new file mode 100644 index 00000000..12e33471 --- /dev/null +++ b/deployment/charts/hapi-fhir/templates/elasticsearch.yaml @@ -0,0 +1,96 @@ +# Elasticsearch (single node): the Hibernate Search index next to PostgreSQL, which is +# what answers _text and _content. +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: hapi-fhir-es +spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 10Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hapi-fhir-es +spec: + replicas: 1 + strategy: + type: Recreate # single RWO volume — never two pods at once + selector: + matchLabels: + app: hapi-fhir-es + template: + metadata: + labels: + app: hapi-fhir-es + spec: + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + seccompProfile: + type: RuntimeDefault + containers: + - name: elasticsearch + image: docker.elastic.co/elasticsearch/elasticsearch:8.19.19 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] + ports: + - name: http + containerPort: 9200 + env: + - name: discovery.type + value: single-node + - name: cluster.name + value: hapi-fhir + # No authentication: reachable only inside the cluster (ClusterIP Service, + # no HTTPRoute). + - name: xpack.security.enabled + value: "false" + - name: xpack.ml.enabled + value: "false" + # The nodes keep the default vm.max_map_count, too low for mmap'd indices. + - name: node.store.allow_mmap + value: "false" + # Deliberately small, with the limit below: the cluster has little spare + # memory, and search timings are meant to show where this saturates. + - name: ES_JAVA_OPTS + value: "-Xms512m -Xmx512m" + resources: + limits: + memory: 1200Mi + startupProbe: + httpGet: + path: /_cluster/health?wait_for_status=yellow&timeout=1s + port: http + failureThreshold: 60 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /_cluster/health?wait_for_status=yellow&timeout=1s + port: http + periodSeconds: 20 + timeoutSeconds: 10 + volumeMounts: + - name: data + mountPath: /usr/share/elasticsearch/data + volumes: + - name: data + persistentVolumeClaim: + claimName: hapi-fhir-es +--- +apiVersion: v1 +kind: Service +metadata: + name: hapi-fhir-es +spec: + selector: + app: hapi-fhir-es + ports: + - port: 9200 + targetPort: http diff --git a/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml b/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml new file mode 100644 index 00000000..9b41c68c --- /dev/null +++ b/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml @@ -0,0 +1,182 @@ +# HAPI FHIR JPA server (R4). +# The ConfigMap is merged on top of the application.yaml in the image. +apiVersion: v1 +kind: ConfigMap +metadata: + name: hapi-fhir-config +data: + application.yaml: | + spring: + autoconfigure: + # The image excludes the Elasticsearch REST client auto-configuration; re-enable it. + exclude: "" + elasticsearch: + uris: http://hapi-fhir-es:9200 + datasource: + hikari: + maximum-pool-size: 30 + jpa: + properties: + hibernate: + search: + enabled: true + schema_management: + strategy: CREATE + backend: + type: elasticsearch + hosts: hapi-fhir-es:9200 + protocol: http + layout: + strategy: ca.uhn.fhir.jpa.search.elastic.IndexNamePrefixLayoutStrategy + analysis: + configurer: ca.uhn.fhir.jpa.search.HapiHSearchAnalysisConfigurers$HapiElasticsearchAnalysisConfigurer + scroll_timeout: 60 + dynamic_mapping: true + schema_management: + settings_file: ca/uhn/fhir/jpa/elastic/index-settings.json + minimal_required_status: YELLOW + minimal_required_status_wait_timeout: 10000 + hapi: + fhir: + # _text / _content indexing (off by default since HAPI FHIR 8.0) + search_index_full_text_enabled: true + # false: Elasticsearch answers only _text / _content, and every other search stays + # in PostgreSQL, so a search straight after a write still sees it. + # true also indexes and answers ordinary search parameters in + # Elasticsearch, which lags a write by its refresh interval. + advanced_lucene_indexing: false + store_resource_in_lucene_index_enabled: false + # Never reuse a cached search: timings measure the search, not the cache. + reuse_cached_search_results_millis: 0 + allow_contains_searches: true +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hapi-fhir +spec: + replicas: 1 + strategy: + type: Recreate # a new version migrates the schema — never two versions at once + selector: + matchLabels: + app: hapi-fhir + template: + metadata: + labels: + app: hapi-fhir + spec: + securityContext: + runAsNonRoot: true + runAsUser: 65532 + runAsGroup: 65532 + fsGroup: 65532 + seccompProfile: + type: RuntimeDefault + initContainers: + - name: wait-for-db + image: postgres:16-alpine + command: ["/bin/sh", "-c"] + args: + - | + until pg_isready -h hapi-fhir-db -p 5432 -U fhir; do + echo "waiting for postgres..."; sleep 5; + done + - name: wait-for-es + image: postgres:16-alpine # for its busybox wget; the HAPI image has no shell + command: ["/bin/sh", "-c"] + args: + - | + until wget -q -O /dev/null "http://hapi-fhir-es:9200/_cluster/health?wait_for_status=yellow&timeout=5s"; do + echo "waiting for elasticsearch..."; sleep 5; + done + containers: + - name: hapi-fhir + # distroless flavour + # (Docker Hub tags carry a -N release suffix; bare v8.12.0 does not exist) + image: hapiproject/hapi:v8.12.0-2 + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] + ports: + - name: http + containerPort: 8080 + - name: http-metrics + containerPort: 8081 + env: + # --- FHIR version: R4 (hapi-fhir-structures-r4) --- + - name: HAPI_FHIR_FHIR_VERSION + value: R4 + # --- database wiring (mirrors the hapi-fhir-jpaserver chart) --- + - name: SPRING_DATASOURCE_URL + value: jdbc:postgresql://hapi-fhir-db:5432/fhir + - name: SPRING_DATASOURCE_USERNAME + value: fhir + - name: SPRING_DATASOURCE_PASSWORD + valueFrom: + secretKeyRef: + name: hapi-fhir-db + key: POSTGRES_PASSWORD + - name: SPRING_DATASOURCE_DRIVERCLASSNAME + value: org.postgresql.Driver + - name: spring.jpa.properties.hibernate.dialect + value: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgresDialect + # --- Elasticsearch and search settings: the hapi-fhir-config ConfigMap --- + - name: SPRING_CONFIG_ADDITIONAL_LOCATION + value: file:/config/ + - name: HAPI_FHIR_USE_APACHE_ADDRESS_STRATEGY + value: "true" + - name: MANAGEMENT_SERVER_PORT + value: "8081" + - name: MANAGEMENT_ENDPOINT_HEALTH_PROBES_ADD_ADDITIONAL_PATHS + value: "true" + - name: MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE + value: "health,prometheus" + startupProbe: + httpGet: + path: /readyz + port: http + failureThreshold: 30 + initialDelaySeconds: 30 + periodSeconds: 10 + readinessProbe: + httpGet: + path: /readyz + port: http + periodSeconds: 20 + timeoutSeconds: 10 + livenessProbe: + httpGet: + path: /livez + port: http + periodSeconds: 20 + timeoutSeconds: 10 + volumeMounts: + - name: tmp + mountPath: /tmp + - name: lucene + mountPath: /app/target + - name: config + mountPath: /config + readOnly: true + volumes: + - name: config + configMap: + name: hapi-fhir-config + - name: tmp + emptyDir: {} + - name: lucene + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: hapi-fhir +spec: + selector: + app: hapi-fhir + ports: + - port: 8080 + targetPort: http diff --git a/deployment/charts/hapi-fhir/templates/postgres.yaml b/deployment/charts/hapi-fhir/templates/postgres.yaml new file mode 100644 index 00000000..bbfcd245 --- /dev/null +++ b/deployment/charts/hapi-fhir/templates/postgres.yaml @@ -0,0 +1,90 @@ +# PostgreSQL: the FHIR resource store. +# The hapi-fhir-db Secret (key POSTGRES_PASSWORD) is not part of the chart; create it +# before installing (see the chart README). +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: hapi-fhir-db +spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 10Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hapi-fhir-db +spec: + replicas: 1 + strategy: + type: Recreate # single RWO volume — never two pods at once + selector: + matchLabels: + app: hapi-fhir-db + template: + metadata: + labels: + app: hapi-fhir-db + spec: + containers: + - name: postgres + image: postgres:16-alpine + # Modest tuning for a single small node. + args: + - -c + - shared_buffers=512MB + - -c + - effective_cache_size=1500MB + - -c + - work_mem=32MB + - -c + - maintenance_work_mem=256MB + - -c + - max_connections=100 + - -c + - shared_preload_libraries=pg_stat_statements + ports: + - containerPort: 5432 + env: + - name: POSTGRES_DB + value: fhir + - name: POSTGRES_USER + value: fhir + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: hapi-fhir-db + key: POSTGRES_PASSWORD + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + readinessProbe: + exec: + command: ["pg_isready", "-U", "fhir", "-d", "fhir"] + initialDelaySeconds: 10 + periodSeconds: 10 + volumeMounts: + - name: data + mountPath: /var/lib/postgresql/data + - name: shm + mountPath: /dev/shm + volumes: + - name: data + persistentVolumeClaim: + claimName: hapi-fhir-db + # The container default of 64Mi is too small for parallel queries. + - name: shm + emptyDir: + medium: Memory + sizeLimit: 1Gi +--- +apiVersion: v1 +kind: Service +metadata: + name: hapi-fhir-db +spec: + selector: + app: hapi-fhir-db + ports: + - port: 5432 + targetPort: 5432 diff --git a/deployment/charts/hapi-fhir/values.yaml b/deployment/charts/hapi-fhir/values.yaml new file mode 100644 index 00000000..17ebdde2 --- /dev/null +++ b/deployment/charts/hapi-fhir/values.yaml @@ -0,0 +1,3 @@ +# This chart has no values. Everything under templates/ is plain Kubernetes YAML with +# no Helm templating: what is in the file is what gets applied. Helm only packages, +# versions, installs and removes it. To change something, edit the manifests. diff --git a/release-please-config.json b/release-please-config.json index 886b0fb5..e8c480fb 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -165,6 +165,23 @@ { "type": "revert", "section": "Reverts" } ] }, + "deployment/charts/hapi-fhir": { + "release-type": "helm", + "component": "helm-charts/hapi-fhir", + "initial-version": "0.1.0", + "changelog-path": "CHANGELOG.md", + "bump-minor-pre-major": false, + "bump-patch-for-minor-pre-major": false, + "draft": false, + "prerelease": false, + "changelog-sections": [ + { "type": "feat", "section": "Features" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "build", "section": "Dependencies" }, + { "type": "refactor", "section": "Code Refactoring" }, + { "type": "revert", "section": "Reverts" } + ] + }, "deployment/terraform/openstack-kubernetes-k3s": { "release-type": "simple", "component": "terraform-modules/openstack-kubernetes-k3s", From 77e0348f76334429a4ce7caa611513c2ef4a6bc0 Mon Sep 17 00:00:00 2001 From: Andrew Holway Date: Fri, 27 Nov 2026 09:45:51 +0000 Subject: [PATCH 2/3] changes from es to os --- deployment/charts/README.md | 4 +- deployment/charts/hapi-fhir/Chart.yaml | 2 +- deployment/charts/hapi-fhir/README.md | 30 +++-- .../charts/hapi-fhir/templates/hapi-fhir.yaml | 23 ++-- .../{elasticsearch.yaml => opensearch.yaml} | 42 +++---- deployment/scripts/minimum_deployment.sh | 107 ++++++++++++++++++ 6 files changed, 165 insertions(+), 43 deletions(-) rename deployment/charts/hapi-fhir/templates/{elasticsearch.yaml => opensearch.yaml} (65%) create mode 100755 deployment/scripts/minimum_deployment.sh diff --git a/deployment/charts/README.md b/deployment/charts/README.md index 57794a24..3d13185d 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -45,8 +45,8 @@ administrative access when using an admin certificate. [OpenSearch upgrade detai ## HAPI FHIR -`hapi-fhir/` runs a HAPI FHIR JPA server (R4) with PostgreSQL and a single-node -Elasticsearch for full-text search. Its manifests are plain Kubernetes YAML with +`hapi-fhir/` runs a HAPI FHIR JPA server (R4) with PostgreSQL and its own single-node +OpenSearch for full-text search. Its manifests are plain Kubernetes YAML with no Helm templating and no values. It needs the `hapi-fhir-db` Secret before installation. [HAPI FHIR chart](hapi-fhir/README.md) diff --git a/deployment/charts/hapi-fhir/Chart.yaml b/deployment/charts/hapi-fhir/Chart.yaml index 5190db50..152a6f22 100644 --- a/deployment/charts/hapi-fhir/Chart.yaml +++ b/deployment/charts/hapi-fhir/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: hapi-fhir -description: HAPI FHIR JPA server (R4) with PostgreSQL and Elasticsearch full-text search +description: HAPI FHIR JPA server (R4) with PostgreSQL and OpenSearch full-text search type: application version: 0.1.0 appVersion: "v8.12.0-2" diff --git a/deployment/charts/hapi-fhir/README.md b/deployment/charts/hapi-fhir/README.md index 3544a4d0..3bb6b04c 100644 --- a/deployment/charts/hapi-fhir/README.md +++ b/deployment/charts/hapi-fhir/README.md @@ -1,7 +1,7 @@ # CogStack HAPI FHIR Helm chart A [HAPI FHIR](https://hapifhir.io/) JPA server (FHIR R4) with PostgreSQL as the -resource store and a single-node Elasticsearch as its full-text index, which is +resource store and a single-node OpenSearch as its full-text index, which is what answers `_text` and `_content` searches. Every other search stays in PostgreSQL, so a search straight after a write still sees it. @@ -9,7 +9,7 @@ PostgreSQL, so a search straight after a write still sees it. | --- | --- | --- | --- | | `hapi-fhir` | `hapiproject/hapi:v8.12.0-2` | `hapi-fhir:8080` | none | | `hapi-fhir-db` | `postgres:16-alpine` | `hapi-fhir-db:5432` | 10Gi PVC | -| `hapi-fhir-es` | `docker.elastic.co/elasticsearch/elasticsearch:8.19.19` | `hapi-fhir-es:9200` | 10Gi PVC | +| `hapi-fhir-opensearch` | `opensearchproject/opensearch:3.9.0` | `hapi-fhir-opensearch:9200` | 10Gi PVC | ## No templating @@ -42,15 +42,15 @@ helm upgrade --install hapi-fhir deployment/charts/hapi-fhir -n cogstack \ --wait --timeout 15m ``` -HAPI waits for PostgreSQL and Elasticsearch, then migrates its schema. The +HAPI waits for PostgreSQL and OpenSearch, then migrates its schema. The first start takes a few minutes. ## Access The chart creates only ClusterIP Services. It has no Ingress or HTTPRoute, because a hostname cannot be set without templating. PostgreSQL and -Elasticsearch are meant to stay inside the cluster; Elasticsearch runs without -authentication. +OpenSearch are meant to stay inside the cluster; OpenSearch runs with its +security plugin off, so without authentication. ```bash kubectl -n cogstack port-forward svc/hapi-fhir 8080:8080 @@ -59,13 +59,13 @@ curl 'http://localhost:8080/fhir/Patient?_text=x&_summary=count' ``` The second request answers `400` (`HAPI-1192`) if HAPI is not using -Elasticsearch. +OpenSearch. To publish the server, route your own Ingress or Gateway API HTTPRoute to the `hapi-fhir` Service on port `8080`. HAPI builds its links from the `X-Forwarded-*` headers the proxy sends. -If resources were stored before Elasticsearch was attached, index them once: +If resources were stored before OpenSearch was attached, index them once: ```bash curl -X POST 'http://localhost:8080/fhir/$reindex' \ @@ -73,9 +73,23 @@ curl -X POST 'http://localhost:8080/fhir/$reindex' \ -d '{"resourceType":"Parameters"}' ``` +## OpenSearch and HAPI + +HAPI reaches OpenSearch through Hibernate Search, whose backend type is named +`elasticsearch` in the configuration. Two things follow from using OpenSearch +there. + +- **No `spring.elasticsearch` settings.** They make HAPI start its Elasticsearch + Java client, which OpenSearch rejects with `406 Not Acceptable`, and HAPI then + fails to start. That client serves only the `$lastn` operation, so `$lastn` + is not available with this chart. +- **A version warning at startup.** Hibernate Search 7.2 in HAPI v8.12.0 logs + `HSEARCH400085: Unknown Elasticsearch version running on the cluster: + 'opensearch:3.9.0'`. Indexing, `_text`, `_content` and `$reindex` work. + ## Sizing -Elasticsearch runs with a 512 MB heap and a 1200Mi memory limit, and uses +OpenSearch runs with a 512 MB heap and a 1200Mi memory limit, and uses `node.store.allow_mmap=false` so the nodes need no `vm.max_map_count` change. PostgreSQL is tuned for about 2 GB of memory. These suit a small shared cluster; edit the manifests for anything larger. diff --git a/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml b/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml index 9b41c68c..1ba89578 100644 --- a/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml +++ b/deployment/charts/hapi-fhir/templates/hapi-fhir.yaml @@ -7,11 +7,10 @@ metadata: data: application.yaml: | spring: - autoconfigure: - # The image excludes the Elasticsearch REST client auto-configuration; re-enable it. - exclude: "" - elasticsearch: - uris: http://hapi-fhir-es:9200 + # No spring.elasticsearch block: it would make HAPI start its Elasticsearch Java + # client (used only for $lastn), which OpenSearch rejects with 406. Hibernate + # Search has its own client, configured under backend below, and that one works + # with OpenSearch. Its backend type is still called elasticsearch. datasource: hikari: maximum-pool-size: 30 @@ -24,7 +23,7 @@ data: strategy: CREATE backend: type: elasticsearch - hosts: hapi-fhir-es:9200 + hosts: hapi-fhir-opensearch:9200 protocol: http layout: strategy: ca.uhn.fhir.jpa.search.elastic.IndexNamePrefixLayoutStrategy @@ -40,10 +39,10 @@ data: fhir: # _text / _content indexing (off by default since HAPI FHIR 8.0) search_index_full_text_enabled: true - # false: Elasticsearch answers only _text / _content, and every other search stays + # false: OpenSearch answers only _text / _content, and every other search stays # in PostgreSQL, so a search straight after a write still sees it. # true also indexes and answers ordinary search parameters in - # Elasticsearch, which lags a write by its refresh interval. + # OpenSearch, which lags a write by its refresh interval. advanced_lucene_indexing: false store_resource_in_lucene_index_enabled: false # Never reuse a cached search: timings measure the search, not the cache. @@ -82,13 +81,13 @@ spec: until pg_isready -h hapi-fhir-db -p 5432 -U fhir; do echo "waiting for postgres..."; sleep 5; done - - name: wait-for-es + - name: wait-for-opensearch image: postgres:16-alpine # for its busybox wget; the HAPI image has no shell command: ["/bin/sh", "-c"] args: - | - until wget -q -O /dev/null "http://hapi-fhir-es:9200/_cluster/health?wait_for_status=yellow&timeout=5s"; do - echo "waiting for elasticsearch..."; sleep 5; + until wget -q -O /dev/null "http://hapi-fhir-opensearch:9200/_cluster/health?wait_for_status=yellow&timeout=5s"; do + echo "waiting for opensearch..."; sleep 5; done containers: - name: hapi-fhir @@ -123,7 +122,7 @@ spec: value: org.postgresql.Driver - name: spring.jpa.properties.hibernate.dialect value: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgresDialect - # --- Elasticsearch and search settings: the hapi-fhir-config ConfigMap --- + # --- OpenSearch and search settings: the hapi-fhir-config ConfigMap --- - name: SPRING_CONFIG_ADDITIONAL_LOCATION value: file:/config/ - name: HAPI_FHIR_USE_APACHE_ADDRESS_STRATEGY diff --git a/deployment/charts/hapi-fhir/templates/elasticsearch.yaml b/deployment/charts/hapi-fhir/templates/opensearch.yaml similarity index 65% rename from deployment/charts/hapi-fhir/templates/elasticsearch.yaml rename to deployment/charts/hapi-fhir/templates/opensearch.yaml index 12e33471..69308a2d 100644 --- a/deployment/charts/hapi-fhir/templates/elasticsearch.yaml +++ b/deployment/charts/hapi-fhir/templates/opensearch.yaml @@ -1,9 +1,10 @@ -# Elasticsearch (single node): the Hibernate Search index next to PostgreSQL, which is -# what answers _text and _content. +# OpenSearch (single node): the Hibernate Search index next to PostgreSQL, which is +# what answers _text and _content. Hibernate Search reaches it through its +# Elasticsearch-compatible backend. apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: hapi-fhir-es + name: hapi-fhir-opensearch spec: accessModes: ["ReadWriteOnce"] resources: @@ -13,18 +14,18 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: - name: hapi-fhir-es + name: hapi-fhir-opensearch spec: replicas: 1 strategy: type: Recreate # single RWO volume — never two pods at once selector: matchLabels: - app: hapi-fhir-es + app: hapi-fhir-opensearch template: metadata: labels: - app: hapi-fhir-es + app: hapi-fhir-opensearch spec: securityContext: runAsNonRoot: true @@ -34,8 +35,8 @@ spec: seccompProfile: type: RuntimeDefault containers: - - name: elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:8.19.19 + - name: opensearch + image: opensearchproject/opensearch:3.9.0 securityContext: allowPrivilegeEscalation: false capabilities: @@ -49,17 +50,18 @@ spec: - name: cluster.name value: hapi-fhir # No authentication: reachable only inside the cluster (ClusterIP Service, - # no HTTPRoute). - - name: xpack.security.enabled - value: "false" - - name: xpack.ml.enabled - value: "false" + # no Ingress or HTTPRoute). The security plugin is off, so no demo + # certificates or users are installed either. + - name: DISABLE_SECURITY_PLUGIN + value: "true" + - name: DISABLE_INSTALL_DEMO_CONFIG + value: "true" # The nodes keep the default vm.max_map_count, too low for mmap'd indices. - name: node.store.allow_mmap value: "false" - # Deliberately small, with the limit below: the cluster has little spare - # memory, and search timings are meant to show where this saturates. - - name: ES_JAVA_OPTS + # Deliberately small, with the limit below, for a cluster with little spare + # memory. + - name: OPENSEARCH_JAVA_OPTS value: "-Xms512m -Xmx512m" resources: limits: @@ -78,19 +80,19 @@ spec: timeoutSeconds: 10 volumeMounts: - name: data - mountPath: /usr/share/elasticsearch/data + mountPath: /usr/share/opensearch/data volumes: - name: data persistentVolumeClaim: - claimName: hapi-fhir-es + claimName: hapi-fhir-opensearch --- apiVersion: v1 kind: Service metadata: - name: hapi-fhir-es + name: hapi-fhir-opensearch spec: selector: - app: hapi-fhir-es + app: hapi-fhir-opensearch ports: - port: 9200 targetPort: http diff --git a/deployment/scripts/minimum_deployment.sh b/deployment/scripts/minimum_deployment.sh new file mode 100755 index 00000000..7e14baf7 --- /dev/null +++ b/deployment/scripts/minimum_deployment.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Deploy the minimum CogStack stack to the current kubectl context: +# HAPI FHIR, OpenSearch and NiFi. +# +# Usage, from anywhere in the repository: +# bash deployment/scripts/minimum_deployment.sh +# +# The namespace is KUBE_NAMESPACE in deployment/env/general.env. The script is safe +# to run again: it keeps existing certificates and Secrets, and upgrades the releases. +# +# Credentials: +# - HAPI FHIR: a random database password, generated on the first run. +# - OpenSearch: the passwords in deployment/env/authentication.env, or the +# OPENSEARCH_*_PASSWORD environment variables. +# - NiFi: NIFI_SINGLE_USER_CREDENTIALS_USERNAME (default admin) and +# NIFI_SINGLE_USER_CREDENTIALS_PASSWORD (at least 12 characters). If the +# password is not set, a random one is generated and not shown. +# +# Not deployed: NGINX and OpenSearch Dashboards. Without NGINX nothing is published +# outside the cluster, and the NiFi NetworkPolicy admits only NGINX pods. Add it with +# make -C deployment certs-nginx k3s-load-certs-nginx helm-install-nginx +# +# Requirements: kubectl, helm, make, openssl, jq, htpasswd and Java keytool. +set -euo pipefail + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +deployment_dir=$(cd -- "$script_dir/.." && pwd) +cd -- "$deployment_dir" + +# shellcheck source=../env/general.env +source ./env/general.env +namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" +certs="${SECURITY_DIR:-$deployment_dir/security}/certificates" + +log() { printf '\n==> %s\n' "$*"; } + +secret_exists() { + [[ -n $(kubectl -n "$namespace" get secret "$1" --ignore-not-found -o name) ]] +} + +for tool in kubectl helm make openssl jq htpasswd keytool; do + if ! command -v "$tool" >/dev/null 2>&1; then + printf 'Missing required tool: %s\n' "$tool" >&2 + exit 1 + fi +done + +log "Namespace $namespace on context $(kubectl config current-context)" +make setup-k3s-namespace + +# --- HAPI FHIR --------------------------------------------------------------- +log "HAPI FHIR" +# PostgreSQL sets the password only when it first initialises its volume, so an +# existing Secret is kept. +if secret_exists hapi-fhir-db; then + echo "secret/hapi-fhir-db already exists." +else + kubectl -n "$namespace" create secret generic hapi-fhir-db \ + --from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 24)" +fi +helm upgrade --install hapi-fhir charts/hapi-fhir -n "$namespace" \ + --wait --timeout "${HELM_TIMEOUT:-15m}" + +# --- OpenSearch -------------------------------------------------------------- +log "OpenSearch" +# The certificate generators refuse to overwrite, so generate only what is missing. +if [[ ! -e "$certs/root/root-ca.pem" ]]; then + make certs-root +fi +if [[ ! -e "$certs/opensearch/opensearch-shared.crt" ]]; then + CLUSTER_DOMAIN="${CLUSTER_DOMAIN:-cluster.local}" \ + make certs-opensearch-shared KUBE_NAMESPACE="$namespace" +fi +make k3s-load-certs-opensearch +# Skips itself when the bootstrap Secret already exists. +make k3s-load-auth-opensearch +make helm-install-opensearch HELM_VALUES= + +# --- NiFi -------------------------------------------------------------------- +log "NiFi" +if secret_exists nifi-auth; then + echo "secret/nifi-auth already exists." +else + if [[ -z ${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:-} ]]; then + NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=$(openssl rand -hex 16) + export NIFI_SINGLE_USER_CREDENTIALS_PASSWORD + echo "NIFI_SINGLE_USER_CREDENTIALS_PASSWORD is not set: generated a random NiFi password." + echo "To choose one, set it and run: make -C deployment k3s-load-auth-nifi" + fi + make k3s-load-auth-nifi +fi +make helm-install-nifi HELM_TIMEOUT="${HELM_TIMEOUT:-15m}" + +# --- Summary ----------------------------------------------------------------- +log "Deployed to namespace $namespace" +kubectl -n "$namespace" get pods +cat < Date: Fri, 27 Nov 2026 09:54:50 +0000 Subject: [PATCH 3/3] minimum deployment script updates --- deployment/charts/hapi-fhir/README.md | 5 +- .../hapi-fhir/templates/opensearch.yaml | 17 ++- deployment/scripts/minimum_deployment.sh | 135 ++++++++---------- 3 files changed, 71 insertions(+), 86 deletions(-) diff --git a/deployment/charts/hapi-fhir/README.md b/deployment/charts/hapi-fhir/README.md index 3bb6b04c..e7bc729a 100644 --- a/deployment/charts/hapi-fhir/README.md +++ b/deployment/charts/hapi-fhir/README.md @@ -49,8 +49,9 @@ first start takes a few minutes. The chart creates only ClusterIP Services. It has no Ingress or HTTPRoute, because a hostname cannot be set without templating. PostgreSQL and -OpenSearch are meant to stay inside the cluster; OpenSearch runs with its -security plugin off, so without authentication. +OpenSearch are meant to stay inside the cluster; the OpenSearch container +uninstalls its security plugin at startup, so it runs without authentication +and needs no certificates. ```bash kubectl -n cogstack port-forward svc/hapi-fhir 8080:8080 diff --git a/deployment/charts/hapi-fhir/templates/opensearch.yaml b/deployment/charts/hapi-fhir/templates/opensearch.yaml index 69308a2d..53f46331 100644 --- a/deployment/charts/hapi-fhir/templates/opensearch.yaml +++ b/deployment/charts/hapi-fhir/templates/opensearch.yaml @@ -41,6 +41,16 @@ spec: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] + # No authentication: reachable only inside the cluster (ClusterIP Service, + # no Ingress or HTTPRoute). The security plugin is uninstalled before + # OpenSearch starts, so there are no certificates, users or demo + # configuration. The image's entrypoint then starts OpenSearch as usual. + command: + - bash + - -ec + - | + bin/opensearch-plugin remove --purge opensearch-security + exec ./opensearch-docker-entrypoint.sh ports: - name: http containerPort: 9200 @@ -49,13 +59,6 @@ spec: value: single-node - name: cluster.name value: hapi-fhir - # No authentication: reachable only inside the cluster (ClusterIP Service, - # no Ingress or HTTPRoute). The security plugin is off, so no demo - # certificates or users are installed either. - - name: DISABLE_SECURITY_PLUGIN - value: "true" - - name: DISABLE_INSTALL_DEMO_CONFIG - value: "true" # The nodes keep the default vm.max_map_count, too low for mmap'd indices. - name: node.store.allow_mmap value: "false" diff --git a/deployment/scripts/minimum_deployment.sh b/deployment/scripts/minimum_deployment.sh index 7e14baf7..7441d4fc 100755 --- a/deployment/scripts/minimum_deployment.sh +++ b/deployment/scripts/minimum_deployment.sh @@ -2,106 +2,87 @@ # Deploy the minimum CogStack stack to the current kubectl context: # HAPI FHIR, OpenSearch and NiFi. # -# Usage, from anywhere in the repository: # bash deployment/scripts/minimum_deployment.sh # -# The namespace is KUBE_NAMESPACE in deployment/env/general.env. The script is safe -# to run again: it keeps existing certificates and Secrets, and upgrades the releases. +# Each service is rendered with `helm template` to deployment/rendered/.yaml +# and applied with `kubectl apply`. The namespace is KUBE_NAMESPACE in +# deployment/env/general.env. Safe to run again: existing Secrets are kept. # -# Credentials: -# - HAPI FHIR: a random database password, generated on the first run. -# - OpenSearch: the passwords in deployment/env/authentication.env, or the -# OPENSEARCH_*_PASSWORD environment variables. -# - NiFi: NIFI_SINGLE_USER_CREDENTIALS_USERNAME (default admin) and -# NIFI_SINGLE_USER_CREDENTIALS_PASSWORD (at least 12 characters). If the -# password is not set, a random one is generated and not shown. +# The charts read four Secrets that cannot be committed, so step 1 creates any +# that are missing. OpenSearch users and their passwords come from +# deployment/env/authentication.env. # -# Not deployed: NGINX and OpenSearch Dashboards. Without NGINX nothing is published -# outside the cluster, and the NiFi NetworkPolicy admits only NGINX pods. Add it with -# make -C deployment certs-nginx k3s-load-certs-nginx helm-install-nginx -# -# Requirements: kubectl, helm, make, openssl, jq, htpasswd and Java keytool. +# Requirements: kubectl, helm, openssl, htpasswd. set -euo pipefail -script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) -deployment_dir=$(cd -- "$script_dir/.." && pwd) -cd -- "$deployment_dir" - -# shellcheck source=../env/general.env +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." source ./env/general.env -namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" -certs="${SECURITY_DIR:-$deployment_dir/security}/certificates" - -log() { printf '\n==> %s\n' "$*"; } +ns=$KUBE_NAMESPACE +mkdir -p rendered -secret_exists() { - [[ -n $(kubectl -n "$namespace" get secret "$1" --ignore-not-found -o name) ]] -} +kubectl create namespace "$ns" --dry-run=client -o yaml | kubectl apply -f - -for tool in kubectl helm make openssl jq htpasswd keytool; do - if ! command -v "$tool" >/dev/null 2>&1; then - printf 'Missing required tool: %s\n' "$tool" >&2 - exit 1 - fi -done +# --- 1. Secrets ---------------------------------------------------------------- +secret_missing() { ! kubectl -n "$ns" get secret "$1" >/dev/null 2>&1; } -log "Namespace $namespace on context $(kubectl config current-context)" -make setup-k3s-namespace - -# --- HAPI FHIR --------------------------------------------------------------- -log "HAPI FHIR" -# PostgreSQL sets the password only when it first initialises its volume, so an -# existing Secret is kept. -if secret_exists hapi-fhir-db; then - echo "secret/hapi-fhir-db already exists." -else - kubectl -n "$namespace" create secret generic hapi-fhir-db \ +# HAPI FHIR: PostgreSQL password. +if secret_missing hapi-fhir-db; then + kubectl -n "$ns" create secret generic hapi-fhir-db \ --from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 24)" fi -helm upgrade --install hapi-fhir charts/hapi-fhir -n "$namespace" \ - --wait --timeout "${HELM_TIMEOUT:-15m}" -# --- OpenSearch -------------------------------------------------------------- -log "OpenSearch" -# The certificate generators refuse to overwrite, so generate only what is missing. -if [[ ! -e "$certs/root/root-ca.pem" ]]; then - make certs-root -fi -if [[ ! -e "$certs/opensearch/opensearch-shared.crt" ]]; then - CLUSTER_DOMAIN="${CLUSTER_DOMAIN:-cluster.local}" \ - make certs-opensearch-shared KUBE_NAMESPACE="$namespace" +# NiFi: key that encrypts sensitive values in the flow. +if secret_missing nifi-auth; then + kubectl -n "$ns" create secret generic nifi-auth \ + --from-literal=NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" fi -make k3s-load-certs-opensearch -# Skips itself when the bootstrap Secret already exists. -make k3s-load-auth-opensearch -make helm-install-opensearch HELM_VALUES= -# --- NiFi -------------------------------------------------------------------- -log "NiFi" -if secret_exists nifi-auth; then - echo "secret/nifi-auth already exists." -else - if [[ -z ${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:-} ]]; then - NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=$(openssl rand -hex 16) - export NIFI_SINGLE_USER_CREDENTIALS_PASSWORD - echo "NIFI_SINGLE_USER_CREDENTIALS_PASSWORD is not set: generated a random NiFi password." - echo "To choose one, set it and run: make -C deployment k3s-load-auth-nifi" - fi - make k3s-load-auth-nifi +# OpenSearch: the security plugin requires TLS between nodes. One self-signed +# certificate, which every node presents and trusts, is enough. Its subject must +# match plugins.security.nodes_dn in charts/opensearch/config/opensearch.yml. +if secret_missing opensearch-node-tls; then + tls=$(mktemp -d) + openssl req -x509 -newkey rsa:4096 -nodes -days 1460 \ + -subj "/C=UK/ST=London/L=UK/O=cogstack/OU=cogstack/CN=opensearch-shared" \ + -keyout "$tls/node.key" -out "$tls/node.crt" + kubectl -n "$ns" create secret generic opensearch-node-tls \ + --from-file=node.crt="$tls/node.crt" \ + --from-file=node.key="$tls/node.key" \ + --from-file=ca.crt="$tls/node.crt" + rm -rf -- "$tls" fi -make helm-install-nifi HELM_TIMEOUT="${HELM_TIMEOUT:-15m}" -# --- Summary ----------------------------------------------------------------- -log "Deployed to namespace $namespace" -kubectl -n "$namespace" get pods +# OpenSearch: users, roles and role mappings (opensearch-security-bootstrap). +# Does nothing when the Secret already exists. +bash scripts/security/load_opensearch_auth.sh opensearch + +# --- 2. Render and apply ------------------------------------------------------- +helm template hapi-fhir charts/hapi-fhir > rendered/hapi-fhir.yaml +kubectl -n "$ns" apply -f rendered/hapi-fhir.yaml + +# The upstream OpenSearch chart is a dependency, downloaded into charts/opensearch/charts. +helm repo add opensearch https://opensearch-project.github.io/helm-charts/ --force-update +helm dependency build charts/opensearch +helm template opensearch charts/opensearch --skip-tests \ + --set-file 'opensearch.config.opensearch\.yml=charts/opensearch/config/opensearch.yml' \ + > rendered/opensearch.yaml +kubectl -n "$ns" apply -f rendered/opensearch.yaml + +helm template cogstack-nifi charts/nifi > rendered/nifi.yaml +kubectl -n "$ns" apply -f rendered/nifi.yaml + +# --- 3. Status ----------------------------------------------------------------- +kubectl -n "$ns" get pods cat <