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.
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:27017GO_DEMO_2_DB_PORT_27017_TCP_ADDR=10.0.0.250GO_DEMO_2_DB_PORT_27017_TCP_PROTO=tcpGO_DEMO_2_DB_PORT_27017_TCP_PORT=27017GO_DEMO_2_DB_PORT_27017_TCP=tcp://10.0.0.250:27017GO_DEMO_2_DB_SERVICE_HOST=10.0.0.250GO_DEMO_2_DB_SERVICE_PORT=27017
The first five variables are using the Docker format. If you already worked with Docker networking, you should be familiar with them. At least, if you’re familiar with the way Swarm ...
Access this course and 1500+ top-rated courses and projects.