kubernetes dns lookup of microservice

给你一囗甜甜゛ 提交于 2019-12-06 05:49:22

First off this is documented throughly. In any case if you want to query DNS to find out where things are running you can do so if you know the service name by pointing at:

my-svc.my-namespace.svc.cluster.local

Additionally, if you also want to abstract port numbers and are OK with knowing a port name you can query SRV records and get both port numbers as well as CNAME:

_my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster.local

For your specific example this would be something like (assuming default namespace):

_redis-client._tcp.redis-service.default.svc.cluster.local

Querying SRV records is more reliable than depending on environment variables because if during the lifetime of the pod, an external service changes location, environment variables can't be re-injected, but re-querying DNS records will yield updated results.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!