My kubernetes students are moving towards making their pods interact with each other. Along those lines, they need to find a good approach to service discovery, i.e. how to find a healthy instance of a service that another service wants to consume. A good way to do (server-side) discovery is to make use of k8s'es DNS subsystem. All a calling service has to do is using the target service's FQDN (fully qualified domain name). The structure of a FQDN in k8s is this:
http://{service name}.{namespace}.svc.{cluster}.local:{service port}
Example: if the service you want to reach out to
- is named "phonebook"
- is running in the "default" namespace
- in cluster "explorer"
- on port 8080
...then the fully qualified domain name to use in your http request would be
http://phonebook.default.svc.explorer.local:8080