最近隨著 DC/OS 和 k8s 的流行,很多基礎(chǔ)服務(wù)都不需要我們開發(fā)管理了 (例如服務(wù)發(fā)現(xiàn))嚼蚀,這樣大家可以把更多精力放在業(yè)務(wù)上本冲。下面我們列舉一下常用的服務(wù)發(fā)現(xiàn)方案
-
k8s 自帶的 Kube-DNS
Kube-DNS 可以用 CoreDNS 替代
-
mesos-DNS
Service iscovery through DNS, however, has some limitations that include:
- DNS does not identify service ports, unless you use an SRV query; most apps are not able to use SRV records “out of the box.”
- DNS does not have fast failover.
- DNS records have a TTL (time to live) and Mesos-DNS uses polling to create the DNS records; this can result in stale records.
- DNS records do not provide any service health data.
- Some applications and libraries do not correctly handle multiple A records; in some cases the query might be cached and not correctly reloaded as required.
-
marathon-lb
To address mesos-dns's known problem, mesosphere provide a tool for Marathon called Marathon Load Balancer, or marathon-lb. 可以參考 https://mesosphere.com/blog/dcos-marathon-lb/ 和 https://mesosphere.com/blog/service-discovery-and-load-balancing-with-dcos-and-marathon-lb-part-2/。
-
基于 nginx-proxy 實現(xiàn)的服務(wù)發(fā)現(xiàn)
https://github.com/jwilder/nginx-proxy鞍帝, 這個方案和 marathon-lb 的想法非常類似升酣。
-
基于zk/consul/etcd 開發(fā)的服務(wù)發(fā)現(xiàn)
這種方式需要開發(fā)人員自己實現(xiàn)服務(wù)發(fā)現(xiàn)的功能舷暮,目前大多數(shù)公司使用 consul 作為服務(wù)發(fā)現(xiàn)的比較多,以為它使用簡單噩茄,功能齊全下面。
現(xiàn)在開發(fā)一套系統(tǒng)不需要自己寫服務(wù)發(fā)現(xiàn)的代碼了, 可以直接使用 k8s or mesos/marathon 和 marathon-lb 來實現(xiàn)绩聘, 節(jié)省了很多時間沥割, 而且這也是主流。