Skip to content

Latest commit

 

History

History
126 lines (55 loc) · 15.9 KB

etcd.md

File metadata and controls

126 lines (55 loc) · 15.9 KB

etcd 介绍

etcd 本身是一个可以用的存储系统,在 kubernetes 生态中,使用其来存取各种状态。

etcd is a distributed reliable key-value store for the most critical data of a distributed system, with a focus on being:

  • Simple: well-defined, user-facing API (gRPC)
  • Secure: automatic TLS with optional client cert authentication
  • Fast: benchmarked 10,000 writes/sec
  • Reliable: properly distributed using Raft

etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines. It’s open-source and available on GitHub. etcd gracefully handles leader elections during network partitions and will tolerate machine failure, including the leader.

Your applications can read and write data into etcd. A simple use-case is to store 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 the consistency guarantees to implement database leader elections or do distributed locking across a cluster of workers

coreos 开发的分布式服务系统,内部采用 raft 协议作为一致性算法。作为服务发现系统,有以下的特点:

  • 简单:安装配置简单,而且提供了 HTTP API 进行交互,使用也很简单
  • 安全:支持 SSL 证书验证
  • 快速:根据官方提供的 benchmark 数据,单实例支持每秒 2k+ 读操作
  • 可靠:采用 raft 算法,实现分布式系统数据的可用性和一致性

https://github.com/coreos/etcd/tree/master/etcdctl

安装

第一种

brew install etcd

==> Downloading https://homebrew.bintray.com/bottles/etcd-3.2.10.high_sierra.bottle.tar.gz

######################################################################## 100.0%

==> Pouring etcd-3.2.10.high_sierra.bottle.tar.gz

==> Caveats

To have launchd start etcd now and restart at login:

  brew services start etcd

Or, if you don't want/need a background service you can just run:

  etcd

==> Summary

🍺  /usr/local/Cellar/etcd/3.2.10: 9 files, 52.0MB

https://coreos.com/etcd/docs/latest/v2/docker_guide.html

这里指的安装,并且在 Kubernetes 下。

## Reading and writing to etcd

第一种是通过 ctl 的方式来进行读写

$ etcdctl set /message Hello

Hello

$ etcdctl get /message

Hello

$ etcdctl rm /message

还有一种是通过 http 的方式:

$ curl -X PUT http://127.0.0.1:2379/v2/keys/message -d value="Hello"

{"action":"set","node":{"key":"/message","value":"Hello","modifiedIndex":4,"createdIndex":4}}

$ curl http://127.0.0.1:2379/v2/keys/message

{"action":"get","node":{"key":"/message","value":"Hello","modifiedIndex":4,"createdIndex":4}}

$ curl -X DELETE http://127.0.0.1:2379/v2/keys/message

{"action":"delete","node":{"key":"/message","modifiedIndex":19,"createdIndex":4}}

## Reading and writing from inside a container

Reading and writing from inside a container

REF: