Migrating ODK Aggregate from Fargate to Azure Kubernetes Service (part 2)

March 12, 2019 ☼ #kubernetes#labnotes#migratingodktok8s#odkmigrating-odk-to-k8s

I’m working on deploying an Aggregate 2.0 instance to Kubernetes in the cleanest possible way, and documenting my progress in these lab notes.

More Config Tweaks, yay

So the good news is: my PR got accepted! The bad news is: I still need to do more configuration work. 😞

The best way in k8s to configure Pods is using ConfigMaps or Secrets. With both ConfigMaps and Secrets, it’s possible to bind mount the contents of a key/value pair into an appropriately named file in a directory on the container (or inject them as environment variables). This will allow me to set a security.properties value in a ConfigMap (or Secret) and mount it into the appropriate spot for Aggregate.

Unfortunately, it’s not possible to mount individual files into existing directories, so it’s not feasible to simply mount a file such as security.properties into ODKs configuration directory directly.

This means I needed to tweak the Docker entrypoint.sh file a bit to create symbolic links from a configuration directory into the appropriate web app directory in ODK.

This new code allows the bind-mounting of config files to /etc/config/. Any environmental variables that are set will override the values in those files, as was already the case.

The great part about this is that it also works without k8s, using a simple bind mount passed to Docker, such as:

docker run -d -p 8080:8080 -it \
--env DB_USERNAME=brett
--mount type=bind,source="$(pwd)"/src/main/resources/odk-settings.xml,target=/etc/config/odk-settings.xml,readonly \
--mount type=bind,source="$(pwd)"/src/main/resources/jdbc.properties,target=/etc/config/jdbc.properties,readonly \
--mount type=bind,source="$(pwd)"/src/main/resources/security.properties,target=/etc/config/security.properties,readonly \
--name=aggregate aggregate:latest

In this case, whatever is in ./src/main/resources/jdbc.properties.example gets mounted to /etc/config/jdbc.properties which is symlinked into ${AGGREGATE_CONF_DIR}/jdbc.properties, where ODK Aggregate reads it.

The DB_USERNAME in this example is also being overriden using environment variables to brett,” instead of whatever is specified in that file.

After submitting a PR for these changes, the next step for me will be to finally spin this up in Minikube on my machine.