kubenetes:基于DNS的Kubernetes服务发现规范

背景:
kubenetes可以使用环境变量,DNS做服务发现,服务解析,本文介绍DNS方式的服务发现规范

kubenetes默认提供的是 Kube-DNS ,实际环境中使用的可能是core-dns。尝试性翻译了一下官方关于DNS的服务发现规范,感觉没有英文贴切,作为一个备注文档,协助自己理解吧。

1 - Schema Version
This document describes version 1.0.1 of the schema.

2 - Resource Records
Any DNS-based service discovery solution for Kubernetes must provide the resource records (RRs) described below to be considered compliant with this specification.

2.1 - Definitions
In the RR descriptions below, values not in angle brackets, < >, are literals. The meaning of the values in angle brackets are defined below or in the description of the specific record.

= configured cluster domain, e.g. cluster.local
= a Namespace
= the standard DNS time-to-live value for the record
In the RR descriptions below, the following definitions should be used for words in italics.

hostname

In order of precedence, the hostname of an endpoint is:
The value of the endpoint’s hostname field.
A unique, system-assigned identifier for the endpoint. The exact format and source of this identifier is not prescribed by this specification. However, it must be possible to use this to identify a specific endpoint in the context of a Service. This is used in the event no explicit endpoint hostname is defined.
ready

An endpoint is considered ready if its address is in the addresses field of the EndpointSubset object, or the corresponding service has the service.alpha.kubernetes.io/tolerate-unready-endpoints annotation set to true.
All comparisons between query data and data in Kubernetes are case-insensitive.

2.2 - Record for Schema Version
There must be a TXT record named dns-version.. that contains the semantic version of the DNS schema in use in this cluster.

Record Format:
dns-version.. IN TXT
Question Example:
dns-version.cluster.local. IN TXT
Answer Example:
dns-version.cluster.local. 28800 IN TXT “1.0.0”

2.3 - Records for a Service with ClusterIP
Given a Service named in Namespace with ClusterIP , the following records must exist.

2.3.1 - A Record
Record Format:
..svc.. IN A
Question Example:
kubernetes.default.svc.cluster.local. IN A
Answer Example:
kubernetes.default.svc.cluster.local. 4 IN A 10.3.0.1

2.3.2 - SRV Records
For each port in the Service with name and number using protocol , an SRV record of the following form must exist.

Record Format:
....svc.. IN SRV ..svc..
The priority and weight are numbers as described in RFC2782 and whose values are not prescribed by this specification.

Unnamed ports do not have an SRV record.

Question Example:
_https._tcp.kubernetes.default.svc.cluster.local. IN SRV
Answer Example:
_https._tcp.kubernetes.default.svc.cluster.local. 30 IN SRV 10 100 443 kubernetes.default.svc.cluster.local.
The Additional section of the response may include the Service A record referred to in the SRV record.

2.3.3 - PTR Record
Given Service ClusterIP ..., a PTR record of the following form must exist.

Record Format:
....in-addr.arpa. IN PTR ..svc..
Question Example:
1.0.3.10.in-addr.arpa. IN PTR
Answer Example:
1.0.3.10.in-addr.arpa. 14 IN PTR kubernetes.default.svc.cluster.local.
2.4 - Records for a Headless Service
Given a headless Service in Namespace (i.e., a Service with no ClusterIP), the following records must exist.

2.4.1 - A Records
There must be an A record for each ready endpoint of the headless Service with IP address as shown below. If there are no ready endpoints for the headless Service, the answer should be NXDOMAIN.

Record Format:
..svc.. IN A
Question Example:
headless.default.svc.cluster.local. IN A
Answer Example:
headless.default.svc.cluster.local. 4 IN A 10.3.0.1
headless.default.svc.cluster.local. 4 IN A 10.3.0.2
headless.default.svc.cluster.local. 4 IN A 10.3.0.3

There must also be an A record of the following form for each ready endpoint with hostname of and IP address . If there are multiple IP addresses for a given hostname, then there must be one such A record returned for each IP.

Record Format:
...svc.. IN A
Question Example:
my-pet.headless.default.svc.cluster.local. IN A
Answer Example:
my-pet.headless.default.svc.cluster.local. 4 IN A 10.3.0.100

2.4.2 - SRV Records
For each combination of ready endpoint with hostname of , and port in the Service with name and number using protocol , an SRV record of the following form must exist.

Record Format:
....svc.. IN SRV ...svc..
This implies that if there are N ready endpoints and the Service defines M named ports, there will be N ✖️ M SRV RRs for the Service.

The priority and weight are numbers as described in RFC2782 and whose values are not prescribed by this specification.

Unnamed ports do not have an SRV record.

Question Example:
_https._tcp.headless.default.svc.cluster.local. IN SRV
Answer Example:
_https._tcp.headless.default.svc.cluster.local. 4 IN SRV 10 100 443 my-pet.headless.default.svc.cluster.local.
_https._tcp.headless.default.svc.cluster.local. 4 IN SRV 10 100 443 my-pet-2.headless.default.svc.cluster.local.
_https._tcp.headless.default.svc.cluster.local. 4 IN SRV 10 100 443 438934893.headless.default.svc.cluster.local.
The Additional section of the response may include the A records referred to in the SRV records.

2.4.3 - PTR Records
Given a ready endpoint with hostname of and IP address ..., a PTR record of the following form must exist.

Record Format:
....in-addr.arpa. IN PTR ...svc..
Question Example:
100.0.3.10.in-addr.arpa. IN PTR
Answer Example:
100.0.3.10.in-addr.arpa. 14 IN PTR my-pet.headless.default.svc.cluster.local.

2.5 - Records for External Name Services

Given a Service named in Namespace with ExternalName , a CNAME record named ..svc. pointing to must exist.

Record Format:
..svc.. IN CNAME .
Question Example:
foo.default.svc.cluster.local. IN A
Answer Example:
foo.default.svc.cluster.local. 10 IN CNAME www.example.com.
www.example.com. 28715 IN A 192.0.2.53

2.6 - Deprecated Records
Kube-DNS versions prior to implementation of this specification also replied with an A record of the form below for any values of , , , and between 0 and 255:

Record Format:
---..pod.. IN A ...
This behavior is deprecated but is required to satisfy this specification. It will be removed from a future version of the specification.

3 - Schema Extensions
Specific implementations may choose to extend this schema, but the RRs in this document must be a subset of the RRs produced by the implementation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值