最近在把服务迁移到云上(docker+k8s)的时候,发现k8s是基于etcd做分布式资源管理的,etcd和zk在的核心都是做分布式服务的注册中心(统一资源配置),用法上略有不同。

从官网上来看:

ETCD:

etcd is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of machines. It gracefully handles leader elections during network partitions and can tolerate machine failure, even in the leader node.

Applications of any complexity, from a simple web app to Kubernetes, can read data from and write data into etcd.

Your applications can read from and write data into etcd. A simple use case is storing database connection details or feature flags in etcd as key-value pairs. These values can be watched, allowing your app to reconfigure itself when they change. Advanced uses take advantage of etcd’s consistency guarantees to implement database leader elections or perform distributed locking across a cluster of workers.

etcd is open source, available on GitHub, and backed by the Cloud Native Computing Foundation.

etcd是为一个需要被分布式系统或集群提供了强一致性分布式键值数据库,它优雅的处理了当出现网路阻断也能容忍机器宕机(哪怕是leader结点)。

任何复杂度的应用,一个简单的web界面到k8s,都可以在etcd上读写数据。

你的应用可以再etcd上读写数据。一个简单的例子就是保存数据库连接信息或者特殊的数据的键值在etcd上。这些值可以被监听,当配置变化的时候你的app可以重新配置。适当的采用etcd的一致性优势可以用来保证数据库选举或者对一组工作施加分布式锁。

ETCD提供https协议的的restful风格的接口,1000并发,选举采用raft算法。

 

ZK:

Apache ZooKeeper is an effort to develop and maintain an open-source server which enables highly reliable distributed coordination.

ZK是一个致力于开发和维护一个开源高可用可信赖的分布式一致服务。

ZK解决了一个痛点,在zk出来之前,大量不同形式的分布式系统都有各自的分布式同步工具,不同的配置中心,比较混乱而且难以维护。ZK用了一套简单的接口实现了中心化的一致性服务。

ZKClient和ZKServer之间采用Socket连接(四层协议)

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐