Services can be discovered through two principal modes; environment variables and DNS.
Every Pod gets environment variables for each of the active Services. They are provided in the same format as what Docker links expect, as well with the simpler Kubernetes-specific syntax.
Let's take a look at the environment variables available in one of the Pods we're running.
POD_NAME=$(kubectl get pod \ --no-headers \ -o=custom-columns=NAME:.metadata.name \ -l type=api,service=go-demo-2 \ | tail -1) kubectl exec $POD_NAME env
The output, limited to the environment variables related to the go-demo-2-db service, is as follows:
GO_DEMO_2_DB_PORT=tcp://10.0.0.250:27017 GO_DEMO_2_DB_PORT_27017_TCP_ADDR=10.0.0.250 GO_DEMO_2_DB_PORT_27017_TCP_PROTO=tcp GO_DEMO_2_DB_PORT_27017_TCP_PORT=27017 GO_DEMO_2_DB_PORT_27017_TCP=tcp://10.0.0.250:27017...