I'm setting up a MySQL service on an Openshift container, but I can't access it from the rest of the services.
According to the documentation (https://docs.openshift.com/online/dev_guide/environment_variables.html#automatically-added-environment-variables), when a service is created, the X_SERVICE_HOST
and X__SERVICE_PORT
environment vbles are populated to the rest of the services, but I can't seem to be able to access them from my Java service (using the ${MYSQL_SERVICE_HOST}
placeholder on a .properties
file).
Previously I had been able to connect to a MySQL db using the Cluster IP
value on the service definition, but it doesn't work either, I have tried to import the mysql secret on my Java service, which is supposed to import the env variables such as username, pwd, etc. but it doesn't import the hostname and port.
As stated in this thread (https://github.com/openshift/origin/issues/10401) I have tried to create a MySQL service named MYSQL
, but it fails due to the upper casing.
How should I propagate the env vbles to other services?
Thank you.
Edit: The issue was finally solved, the MySQL URL connection format was wrong, and it contained an extra /
somewhere, after I fixed that the vbles propagated correctly.
The issue was finally solved, the MySQL URL connection format was wrong, and it contained an extra / somewhere, after I fixed that the vbles propagated correctly.
These environment variables will only exist on the pod where the service manifest is selecting. For example if the service manifest selector matches the pod labels, then only those pods will have the environment variables. Other pods will not see those environment variables.
From your java application simply refer to the mysql service name and the port it exposes, and you should be good to go. But make sure that your java client and mysql are on the same namespace / project.
Ordering may be the issue here. I believe the service will need to be created before any of the deployment configs, replication controllers etc that consume them as env vars.