...

>

Discovering Services

Discovering Services

In this lesson, we will go through the discovery process of Services.

Discovering Services

Services can be discovered through two principal modes:

  • Environment variables
  • 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.

Shell
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.

Shell
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
GO_DEMO_2_DB_SERVICE_HOST=10.0.0.250
GO_DEMO_2_DB_SERVICE_PORT=27017

The first five variables are using the Docker ...

Access this course and 2000+ top-rated courses and projects.