Service Discovery Environment variables issue in Kubernetes

8/24/2017

I am using k8s 1.5 and am stuck in one issue. I am trying to deploy 2 pods and related service. We can consider one as UI and another as DB. I have seen that using Service Discovery, we can achieve the connectivity between both the pods.

Problem 1: While getting inside the container of UI Pod, if I am entering env then, I am getting the env variables of Kubernetes service, but I am not getting the env variables of DB Pod. And according to my knowledge, whenever we run any pod then it exposes two variable and i.e SERVICE_HOST and SERVICE_PORT and that should be available to all the pods in that namespace.

Problem 2: Sometimes the UI Pod doesnot show its own variable also, and after retry sometimes it will come. Means it takes time show the environment variable of itself.

Can Anyone suggest me what to do in this scenario ? Does the environment variables maintain orders. If anyone have any nice example then pls let me know.

Note: Both deployment and service files are deployed on the same namespace.

-- Nikit Swaraj
kubernetes

1 Answer

8/24/2017

In the examples that I've seen (https://github.com/kubernetes/kubernetes/blob/master/examples/guestbook-go/main.go, line 77), they use the service dns name instead of environment variables (just like you do when linking containers in docker). The same happens with Helm charts (https://github.com/kubernetes/charts/blob/master/stable/wordpress/templates/deployment.yaml), where in all deployments they use the service name and the port, which is something known (in the case of Helm, generated at deployment time). Would it work for you to directly use the service name and the port?

-- Javier Salmeron
Source: StackOverflow