Specify host name

I have a dependency between multiple services running on kubernetes (deployments). The main service requires the host name specified as environment variable. Is there any way to achieve this.

Below is the config-map of main service, which is used in deployment config (.spec.template.spec.containers.env)

Sample : main service (config-map)

CUBEJS_CUBESTORE_HOST: localhost
CUBEJS_REDIS_URL: redis://redis:6379

The two service are also running on kubernetes i have to let the main service utilize it, for which i require the host name.

What you want is a StatefulSet instead of a Deployment.

Here’s how to generically extract the ordinal and hostname base in a bash script as well:

if ! [[ `hostname` =~ ([A-Za-z0-9_-]+)-([0-9]+)$ ]]; then
    echo "container hostnames must contain ordinals"
    exit 1
fi

HOSTNAME_ORDINAL=${BASH_REMATCH[2]}
HOSTNAME_BASE=${BASH_REMATCH[1]}
2 Likes

Thank you, this was really helpful.