kubernetes dns微服务查询 [英] kubernetes dns lookup of microservice

查看:121
本文介绍了kubernetes dns微服务查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在服务部署中使用的是"dns"而不是"env",则我对kubernetes DNS查找有疑问,

i have a question on the kubernetes DNS lookup, if i am using in my services deployment "dns" instead of "env",

我在集群中使用其他微服务的微服务能否获得所有微服务的dns名称?

Can my microservice using another microservices in the cluster get the dns names of all the microservices?

我得到了这段代码,如果我使用env,那么我会从env获取主机的信息.但是,如果我使用的是dns格式以及如何获取dns名称,是否可以在客户端查询DNS对象?

I get this piece of code, if I use env then I get the the info of host from env. but if I am using dns what format and how do I get the dns names, is there a DNS object I can query on the client side?

if (isset($_GET['cmd']) === true) {
  $host = 'redis-master';
if (getenv('GET_HOSTS_FROM') == 'env') {
  $host = getenv('REDIS_MASTER_SERVICE_HOST');
}

参考: https://github.com/GoogleCloudPlatform/container-engine-samples/blob/master/guestbook/php-redis/guestbook.php

如果有人有示例(最好是nodejs),我可以深入研究.

If someone has examples (preferably nodejs), I can dig into that.

推荐答案

首先,这是

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

此外,如果您也想抽象端口号并且知道端口名称,可以查询SRV记录并获取端口号和CNAME:

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

查询SRV记录比依赖环境变量更为可靠,因为如果在Pod的生命周期内,外部服务更改了位置,则无法重新注入环境变量,但是重新查询DNS记录将产生更新的结果.

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.

这篇关于kubernetes dns微服务查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆