Service Location on Kubernetes using System Environment

I unexpectedly came across the following environment variables table in the AKS documentation.

Apologies for this tangent, but I found this very difficult to troubleshoot, and I want to put it here in case it helps someone. I first noticed this when I was attempting to start my EventStore DB container, and kept getting this very strange error:

Error while parsing options: The option ServicePortEventstore is not a known option. (Parameter ‘ServicePortEventstore’)

This was incredibly confusing to me, since nowhere was I setting this option, as far as I could see. After examining the EventStore documentation, I noticed that EventStore was able to configure itself from the environment, by simply turning any environment variable prepended with EVENTSTORE_ into an option. So, for example, EVENTSTORE_HTTP_PORT would translate to the command line option –http-port.

I concluded, then, that there must be an environment variable EVENTSTORE_SERVICE_PORT_EVENTSTORE being set somewhere. What a strange variable to be set! But, the documentation linked above says that a service named ‘eventstore’ would cause an environment variable EVENTSTORE_SERVICE_PORT to be created. Since there is no –service-port option, the existence of this environment variable causes EventStore to be unable to start up. The answer, then, is to not use the name “eventstore” in your deployments or services. I replaced the string eventstore with esdb, and the error went away.

I’d note, though, that these variables could potentially be quite useful for service discovery. You can enumerate through all the environment variables to determine the service names defined in the cluster, and then use the same environment variables to find endpoint information. The example given in the documentation shows construction of a URL from these environment variables, but I’m sure your imagination can think of better 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: