Skip to main content

Installing Mercury DB (HgDB) on Kubernetes (Helm chart)

Info

The page describes how to build a Kubernetes cluster (kubeadm), how to give it shared storage on NFS, and how to install Mercury DB (HgDB) 3.0 in it with one of the Helm charts from the repository mercury-docker: mercury-single-node (one node) or mercury-three-node-cluster (a cluster of three nodes). Names and addresses (k8s-master, 192.168.10.x, nexus.example.local) are examples; replace them with your own.

The charts are a new way of delivering the system and they start on PostgreSQL 17, so there is no data to migrate (see Upgrading PostgreSQL 14 to 17 for the installations on Docker).

The procedure was verified on clusters with Kubernetes 1.30, containerd, Flannel and an NFS server on the master (Ubuntu): the chart mercury-single-node on the master and two workers, the chart mercury-three-node-cluster on the master and four workers (three of them with 8 GB of RAM, one with 16 GB). The chart mercury-single-node installs one node of Mercury DB with PostgreSQL, Apache ActiveMQ, Ehcache Terracotta, OpenLDAP, the Excel server (POI) and the Nginx load balancer. The chart mercury-three-node-cluster installs three such nodes (see step 6).

StepWhat
1Kubernetes cluster (kubeadm) and Helm
2Shared storage: the NFS server and the clients
3Persistent volumes on NFS
4A non-default registry of images (example)
5Namespace and installation of HgDB
6A cluster of three nodes (chart mercury-three-node-cluster)

1. Kubernetes cluster​

Requirements​

mercury-single-node (one node)mercury-three-node-cluster (three nodes)
Master4 GB of RAM4 GB of RAM
Workers2 workers, 8 GB of RAM eachat least 4 workers, 8 GB of RAM each
Disk of a worker64 GB64 GB
Disk of the masterthe system disk and an additional disk of at least 256 GB for the NFS share (step 2)the same
  • The workers do not need more than 64 GB of disk (128 GB is not necessary): the data lives on NFS, and a worker keeps only the system and the images of the containers.
  • The size of the workers is decisive. The chart sets memory requests and limits for every container (the Excel server (POI) up to 5 GiB, a node of Mercury DB up to 6 GiB), and with smaller workers the Excel (POI) server has problems.
  • The cluster of three nodes asks for about 24 GiB of memory (requests): three nodes of Mercury DB, three Terracotta servers and three Excel servers, plus PostgreSQL, ActiveMQ and OpenLDAP. Both charts together do not fit in a cluster of this size, so install one of them at a time (scale the other one down to zero or remove it).

Example machines​

NameIPvCPURAMDisk
k8s-master192.168.10.1044 GB64 GB, and 256 GB for the NFS share
k8s-worker1192.168.10.1148 GB64 GB
k8s-worker2192.168.10.1248 GB64 GB
k8s-worker3192.168.10.1348 GB64 GB
k8s-worker4192.168.10.1448 GB64 GB

The chart mercury-single-node needs the master and the first two workers. The chart mercury-three-node-cluster needs all four workers.

Several network cards

If the machines have more than one network interface (for example a second card in a separate network), decide which network the cluster and the storage use. Give the address of that network to kubeadm init (--apiserver-advertise-address) and use an address from the same network as the NFS server in the chart (see step 2). A volume mounted through another interface is refused by the NFS server (access denied by server).

Preparation of every node​

  1. Switch off the swap (Kubernetes requires it):

    sudo swapoff -a
    sudo sed -i '/\/swap\.img/s/^/#/' /etc/fstab
  2. Load the kernel modules of the container network:

    cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
    overlay
    br_netfilter
    EOF

    sudo modprobe overlay
    sudo modprobe br_netfilter
  3. Enable the IP routing (sysctl):

    cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-iptables = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    net.ipv4.ip_forward = 1
    EOF

    sudo sysctl --system
  4. Install containerd with SystemdCgroup:

    sudo apt-get update
    sudo apt-get install -y curl gnupg software-properties-common apt-transport-https ca-certificates containerd

    sudo mkdir -p /etc/containerd
    containerd config default | sudo tee /etc/containerd/config.toml
    sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml

    sudo systemctl restart containerd
    sudo systemctl enable containerd
  5. Install kubeadm, kubelet and kubectl (here version 1.30):

    sudo mkdir -p -m 755 /etc/apt/keyrings
    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
    echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

    sudo apt-get update
    sudo apt-get install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl

The master (k8s-master)​

  1. Initialize the cluster (the address is the address of the master in the network of the cluster):

    sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.10.10

    At the end the command prints kubeadm join .... Copy it; the workers need it.

  2. Allow your user to manage the cluster:

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
  3. Install the network of the cluster (Flannel):

    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

The workers​

On every worker (k8s-worker1 and k8s-worker2, and for the cluster of three nodes also k8s-worker3 and k8s-worker4) run the copied command with sudo:

sudo kubeadm join 192.168.10.10:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Problem with joining a node

If a node cannot join (for example the token has expired), generate a new token on the master and print the whole command again. Creating a token does not disturb the nodes that have already joined:

kubeadm token create --print-join-command

On the master check the nodes. After a minute all of them should be Ready:

kubectl get nodes

Helm​

The chart needs Helm 3 on the machine from which you install (here the master). Download the binary of a chosen release and check its checksum:

V=v3.16.4
curl -fsSLO https://get.helm.sh/helm-$V-linux-amd64.tar.gz
curl -fsSL https://get.helm.sh/helm-$V-linux-amd64.tar.gz.sha256sum | sha256sum -c -
tar xzf helm-$V-linux-amd64.tar.gz
mkdir -p $HOME/bin && install -m 755 linux-amd64/helm $HOME/bin/helm
$HOME/bin/helm version --short

Add $HOME/bin to the PATH (for example in ~/.bashrc) or use the full path.

2. NFS server and clients​

The chart keeps all the data (the database, the Lucene indexes, the files of the system) on NFS volumes. The simplest place for the server is the master (or any machine reachable from all the nodes).

  1. Install the server on the machine that shares the files:

    sudo apt-get update
    sudo apt-get install -y nfs-kernel-server
  2. Create the shared directory:

    sudo mkdir -p /srv/nfs/kubedata
    sudo chown -R nobody:nogroup /srv/nfs/kubedata
    sudo chmod 777 /srv/nfs/kubedata
  3. Export it to the network of the cluster. Add the line to /etc/exports (the subnet must contain the addresses from which the nodes connect):

    /srv/nfs/kubedata  192.168.10.0/24(rw,sync,no_subtree_check,no_root_squash)
    sudo exportfs -ra
    sudo systemctl restart nfs-kernel-server
    sudo systemctl enable nfs-kernel-server
    showmount -e localhost
    no_root_squash

    The option no_root_squash is needed: the containers (PostgreSQL, OpenLDAP) write as root and change the owner of their files. Without it the database does not start.

  4. Install the NFS client on every worker (and on every node on which the pods can run):

    sudo apt-get update
    sudo apt-get install -y nfs-common
  5. Check the access from the cluster with a one-off pod. It mounts the share, writes a file and ends with NFS-OK. Put the address of the NFS server in server:

    nfs-test.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: nfs-test
    spec:
    restartPolicy: Never
    containers:
    - name: t
    image: busybox:1.36
    command: ["sh","-c","touch /data/nfs-test-ok && ls -la /data && echo NFS-OK"]
    volumeMounts: [{name: d, mountPath: /data}]
    volumes:
    - name: d
    nfs: {server: 192.168.10.10, path: /srv/nfs/kubedata}
    kubectl apply -f nfs-test.yaml
    kubectl logs nfs-test
    kubectl delete pod nfs-test
    rm /srv/nfs/kubedata/nfs-test-ok

    The error mount.nfs: access denied by server means that the address of the node is outside the subnet from /etc/exports.

3. Persistent volumes on NFS​

The chart creates the persistent volumes (PV) and their claims (PVC) itself, from the section nfsVolumes of values.yaml. You only have to create the directories on the NFS server and give the chart the address of the server and the paths.

Create the directories (on the NFS server):

cd /srv/nfs/kubedata
mkdir -p postgres-db openldap slapd.d certificate_center nginx/conf nginx/html poi-server mercury-upload mercury-lucene
chmod -R 777 postgres-db openldap slapd.d certificate_center nginx poi-server mercury-upload mercury-lucene
Value in nfsVolumesDirectory in the exampleContents
postgresDb.pathpostgres-dbthe data of PostgreSQL
openldap.ldap.path, openldap.slapd.pathopenldap, slapd.dthe data and the configuration of OpenLDAP
certificateCenter.pathcertificate_centerthe certificates of the load balancer
nginx.conf.path, nginx.html.pathnginx/conf, nginx/htmlthe configuration and the pages of Nginx
poiServer.pathpoi-serverthe data of the Excel server
mercury.upload.path, mercury.lucene.pathmercury-upload, mercury-lucenethe uploaded files and the Lucene index

For every volume the chart generates a PV of this shape (the mount option nfsvers=4.2 is set by the chart):

apiVersion: v1
kind: PersistentVolume
metadata:
name: mercurysinglenode-postgres-db-vol1
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.10.10
path: "/srv/nfs/kubedata/postgres-db"
mountOptions:
- nfsvers=4.2

The size (storage) is only a declaration for the binding of the claim; NFS does not enforce it. The names of the PVs are fixed, so one release of the chart per cluster is possible.

4. A non-default registry of images​

By default the chart pulls the images ibpm/mercury, ibpm/postgres, ibpm/activemq, ibpm/ehcache, ibpm/poi-server and ibpm/mercury-lb from Docker Hub (the secret docker-hub of the chart). The example below uses a private registry nexus.example.local:5000 that works over plain HTTP. Replace the address with your own; with a registry over HTTPS with a trusted certificate you only need the pull secret (point b).

a) Allow containerd on every node to use the registry over HTTP. The default config.toml has an empty config_path in the section of the CRI registry, so containerd ignores the directory certs.d. The script below sets it, adds the host file hosts.toml for the registry and restarts containerd. It can be run again without harm (it is idempotent), makes a copy of config.toml first, changes nothing outside of /etc/containerd and contains no credentials (the registry login is the job of the pull secret from point b).

Prepare the script containerd-nexus.sh on a node:

#!/bin/bash
# containerd configuration (a Kubernetes node): pulling images from the HTTP registry nexus.example.local:5000.
# Run ON EVERY NODE as root: sudo bash containerd-nexus.sh
# The script is idempotent. It copies config.toml, sets the config_path of the CRI registry to /etc/containerd/certs.d,
# creates hosts.toml for the registry (HTTP, pull/resolve) and restarts containerd.
# It changes nothing outside of /etc/containerd and has no credentials (imagePullSecret is used to log in to the registry).

set -eu
REGISTRY="${REGISTRY:-nexus.example.local:5000}"
CFG=/etc/containerd/config.toml
CERTS=/etc/containerd/certs.d

if [ "$(id -u)" -ne 0 ]; then
echo "Run as root: sudo bash $0"
exit 1
fi
[ -f "$CFG" ] || { echo "No $CFG"; exit 1; }

# 1. config_path in the section of the CRI registry (only if it is not set yet)
if grep -q "config_path = '$CERTS'" "$CFG"; then
echo "config_path is already set."
else
cp -a "$CFG" "$CFG.bak-$(date +%Y%m%d%H%M%S)"
sed -i "/\[plugins\.'io\.containerd\.cri\.v1\.images'\.registry\]/,/^\s*$/ s|config_path = ''|config_path = '$CERTS'|" "$CFG"
if ! grep -q "config_path = '$CERTS'" "$CFG"; then
echo "ERROR: config_path was not set (check the section [plugins.'io.containerd.cri.v1.images'.registry] in $CFG)."
exit 1
fi
echo "Set config_path = '$CERTS'."
fi

# 2. hosts.toml of the registry
mkdir -p "$CERTS/$REGISTRY"
cat > "$CERTS/$REGISTRY/hosts.toml" <<EOF
server = "http://$REGISTRY"

[host."http://$REGISTRY"]
capabilities = ["pull", "resolve"]
EOF
echo "Written $CERTS/$REGISTRY/hosts.toml"

# 3. restart of containerd (the containers keep running; their management stops for a moment)
systemctl restart containerd
sleep 3
systemctl is-active containerd

# 4. check
if crictl info 2>/dev/null | grep -q "$CERTS"; then
echo "OK: containerd reads $CERTS."
else
echo "WARNING: crictl info does not show $CERTS; check: crictl info | grep -i configPath"
fi

and run it (put your registry in REGISTRY if it differs from the example):

sudo REGISTRY=nexus.example.local:5000 bash containerd-nexus.sh
Image pull error

A node that has not been configured shows the pods in ImagePullBackOff and the event http: server gave HTTP response to HTTPS client. Run the script on that node (this happens for every new worker that joins the cluster later).

The sed pattern in the script fits containerd 2.x (the section io.containerd.cri.v1.images). On containerd 1.x the section is called [plugins."io.containerd.grpc.v1.cri".registry]; set the same config_path there. The name of the registry must resolve on every node (DNS or /etc/hosts).

b) Create the secret with the credentials of the registry in the namespace of the installation (see step 5). Do not store the password in files of a repository:

kubectl -n mercury create secret docker-registry registry-pull \
--docker-server=nexus.example.local:5000 \
--docker-username=<user> --docker-password=<password>

c) Point the chart at the registry in the values file (the section image):

image:
pullSecret: registry-pull
registry: nexus.example.local:5000/ibpm/ # with the ending slash
# mainTag: mercury-hgdb-3.0 # the tag of the auxiliary images
# hgdbTag: mercury-hgdb-3.0.4.45 # the tag of the server image
# activemqTag: mercury-hgdb-3.0-5.19.12 # the tag of the ActiveMQ image (the version of the broker)
# ehcacheTag: mercury-hgdb-3.0-3.10.8 # the tag of the Terracotta image (the version of the kit)
# openldap: nexus.example.local:5000/openldap:ubuntu-24.04 # a full name of the OpenLDAP image

The images must be in the registry under these names and tags (the server image has the tag of the server version, the ActiveMQ and Terracotta images the tags with the version of the product, the others mercury-hgdb-3.0). The OpenLDAP image is by default pulled from Docker Hub (scisoftware/openldap:ubuntu-24.04); set image.openldap if the cluster has no access to it.

Java 17

From version 3.0.4.45 the server and the auxiliary images (ActiveMQ, Terracotta, POI Server) run on Java 17 (Eclipse Temurin). The server image carries its own JDK, so the workers need no Java. A Java 8 client of the web services does not need a change, but a program that uses the Java libraries of the server (mercury-lib) with the server version 3.0.4.45 or later is built with Java 8 or later (the libraries are compiled with release 8).

The Lucene index of an older version (Lucene 7) cannot be read by Lucene 9. After the upgrade the server builds the index again from the database when the index/Case directory is empty (the start script of the container runs mercury-cmd.sh gl Case). Move the old index directories aside before the first start. Backups of the index made with Lucene 7 cannot be restored.

5. Namespace and installation of HgDB​

  1. Get the chart (the directory charts/mercury-single-node of the repository mercury-docker) onto the machine with helm:

    git clone https://github.com/SciSoftwareSlawomirCichy/mercury-docker.git
    cd mercury-docker/charts
  2. Create the namespace and the pull secret (point b of step 4):

    kubectl create namespace mercury
    kubectl -n mercury create secret docker-registry registry-pull --docker-server=... --docker-username=... --docker-password=...
  3. Prepare the file of values my-values.yaml; it overrides values.yaml of the chart, so the chart itself stays unchanged. The example matches the steps above:

    my-values.yaml
    image:
    pullSecret: registry-pull
    registry: nexus.example.local:5000/ibpm/
    url:
    schema: https
    host: 192.168.10.10 # the address under which the clients reach the system
    port: 31443 # NodePort of the load balancer (30000-32767)
    credentials: # change the default passwords
    postgresqlPassword: <password>
    hgdbUserPassword: <password>
    mqAdminPassword: <password>
    mqUserPassword: <password>
    securityToken: <token>
    ldap:
    rootPassword: <password>
    technicalUserPassword: <password>
    nfsVolumes:
    nginx:
    server: 192.168.10.10
    conf: {path: /srv/nfs/kubedata/nginx/conf}
    html: {path: /srv/nfs/kubedata/nginx/html}
    certificateCenter:
    server: 192.168.10.10
    path: /srv/nfs/kubedata/certificate_center
    postgresDb:
    server: 192.168.10.10
    path: /srv/nfs/kubedata/postgres-db
    openldap:
    server: 192.168.10.10
    ldap: {path: /srv/nfs/kubedata/openldap}
    slapd: {path: /srv/nfs/kubedata/slapd.d}
    poiServer:
    server: 192.168.10.10
    path: /srv/nfs/kubedata/poi-server
    mercury:
    server: 192.168.10.10
    upload: {path: /srv/nfs/kubedata/mercury-upload}
    lucene: {path: /srv/nfs/kubedata/mercury-lucene}

    The default passwords and the token in values.yaml are public, so always change them. Store the file with the real values outside of the repository.

  4. Check what the chart generates (optional) and install it:

    helm template mercury ./mercury-single-node -n mercury -f my-values.yaml | grep -n "image:\|server:"
    helm install mercury ./mercury-single-node -n mercury -f my-values.yaml
  5. Watch the start. All the pods should become Running:

    kubectl -n mercury get pods -w
    Order of the start

    The pods wait for their dependencies: the init container wait-for-dependencies checks the ports of PostgreSQL, ActiveMQ, Terracotta, OpenLDAP and the Excel server, so for a while the pods show the state Init:0/1, and the Mercury node starts after its dependencies. When a pod stays in this state for a long time, check what it waits for (the log prints waiting for host:port):

    kubectl -n mercury logs <pod> -c wait-for-dependencies
  6. Check the system. The load balancer is published on the NodePort from url.port, on every node of the cluster. The documentation of the API must answer 200:

    curl -k -o /dev/null -w "%{http_code}\n" https://192.168.10.10:31443/mercury-ws-app/rest/openapi.json

    The database is PostgreSQL 17:

    kubectl -n mercury exec deploy/postgres-db -- psql -U postgres -tc "select version()"

6. Cluster of three nodes (chart mercury-three-node-cluster)​

The chart mercury-three-node-cluster follows the composition of the same name from the repository mercury-docker. It installs:

  • three nodes of Mercury DB: mercury-node1 (the role MASTER of the Lucene index) and mercury-node2, mercury-node3 (SLAVE),
  • for every node its own Terracotta server (ehcache-nodeN), its own Excel server (poi-server-nodeN) and its own volumes poi-server-N, mercury-upload-N and mercury-lucene-N,
  • shared by all nodes: PostgreSQL (max_connections 400), Apache ActiveMQ, OpenLDAP and the Nginx load balancer.

Steps 1 to 4 are the same as for one node. The differences:

  1. Directories on NFS. The paths poiServer.path, mercury.upload.path and mercury.lucene.path in nfsVolumes are bases: the volume of the node N has the path <path>-N. Create three directories for each of them:

    cd /srv/nfs/kubedata
    mkdir -p postgres-db openldap slapd.d certificate_center nginx/conf nginx/html
    mkdir -p poi-server-{1,2,3} mercury-upload-{1,2,3} mercury-lucene-{1,2,3}
    chmod -R 777 .
  2. Installation. The file of values is the same as in step 5 (the nfsVolumes paths are the bases from point 1):

    helm install mercury ./mercury-three-node-cluster -n mercury-cluster -f my-values.yaml

    The names of the persistent volumes start with mercurythreenode-, so they do not collide with the volumes of mercury-single-node (mercurysinglenode-). When both charts are installed, give them different url.port (the NodePort of the load balancer).

  3. Start. The nodes mercury-node2 and mercury-node3 wait until mercury-node1 answers on HTTP (/mercury-ws-app/rest/openapi.json). Thanks to this the first node becomes the MASTER, and the two others start in parallel afterwards. A check of the open port is not enough: Tomcat opens the port 8080 long before the application is ready.

  4. Login sessions. The services of the nodes publish the port 4000 of the Tomcat Cluster. Without it the sessions are not replicated and the GUI asks for the login again after the change of the node (?n=node2). See Login and HTTP sessions in the cluster.

  5. Check the cluster. All the nodes should be ONLINE, and one of them the MASTER:

    curl -k -X POST -H 'Content-Type: application/json' -d '{}' \
    https://192.168.10.10:31443/mercury-ws-app/monitor/NodeMonitorRest/load

    The load balancer spreads the requests over the nodes. A node in maintenance (for example during the restore of the Lucene index) answers 503 with Retry-After, and the load balancer passes the request to another node.

Maintenance​

  • Health checks and restarts. Every component of the charts has startupProbe, livenessProbe and readinessProbe (a TCP check for PostgreSQL, ActiveMQ, OpenLDAP, Ehcache, POI and the load balancer; for a Mercury node the light service /mercury-ws-app/monitor/NodeMonitorRest/load), so a node whose JVM died (for example killed by the out-of-memory killer) is restarted by Kubernetes. A change of the ConfigMap changes the annotation checksum/config of the Mercury nodes, so helm upgrade restarts them (without it the pods keep reading the old configuration).
  • CMIS with Basic authentication uses the OAuth client GIUPortalClient by default (a row of the table MRC_LDAP_OAUTH_SERVICE created by the PostgreSQL init script and the parameters mercury.cmis.security.oauthClientId and mercury.cmis.security.oauthClientSecret of the default mercury.properties; the values cmisOauthClientId and cmisOauthClientSecret of the chart can stay empty). Manage the clients and their secrets in the authentication administration panel.
  • Update of the images or of the values: change the tags or the values and run helm upgrade mercury ./mercury-single-node -n mercury -f my-values.yaml (for the cluster: ./mercury-three-node-cluster -n mercury-cluster).
  • Removal: helm uninstall mercury -n mercury removes the pods, the claims and the persistent volumes of the chart, but leaves the data in the directories on NFS. To start from scratch delete the contents of those directories too (the files belong to root and to the users of the containers, so remove them with sudo on the NFS server or with a one-off pod that mounts the share).
  • Sessions of the login. The chart mercury-single-node installs one node of Mercury, so the replication of HTTP sessions (Tomcat Cluster) is switched off there. It is needed only when several nodes serve the pages behind a load balancer with round-robin, so the chart mercury-three-node-cluster switches it on, see Login and HTTP sessions in the cluster.
  • The load balancer: configuration and certificate. They are created only when the directories nginx/conf and certificate_center on NFS are empty. To change the name of the host in the certificate (sslCertificate.serverName, sslCertificate.domainName) or url.host: scale the load balancer down to zero (kubectl -n <namespace> scale deploy/mercury --replicas=0), empty both directories on the NFS server as root (a container that runs as the user mercury cannot delete the files of the load balancer), run helm upgrade and scale the load balancer up again.
  • Restore of the Lucene index and the restart of the server: the node keeps the restored index after a restart, see Backup and restore of the Lucene index.
  • Disk space. The NFS share holds the database, the indexes and the files of all the nodes, so the disk of the master (the NFS server) is the one that has to be large (256 GB or more).
  • Limits of the connections to the database and the pools of the JDBC: see Database connection pools and the PostgreSQL connection limit. The chart sets postgres.maxConnections (200 by default).