Etcd
Jump to navigation
Jump to search
https://coreos.com/using-coreos/etcd/
etcd is an open-source distributed key value store that provides the backbone of CoreOS clusters and the etcd client runs on each machine in a cluster. etcd gracefully handles master election during network partitions and the loss of the current master.
Your applications can read and write data into etcd. Common examples are storing database connection details, cache settings, feature flags, and more. Features
- Simple, curl-able API (HTTP + JSON)
- Optional SSL client cert authentication
- Benchmarked 1000s of writes/s per instance
- Properly distributed using Raft protocol
- Keys support TTL
- Atomic test and set
- Easily listen for changes to a prefix via HTTP long-polling
Related: CoreOS
First steps
core@core-01 ~ $ etcdctl set /message Hello Hello core@core-01 ~ $ etcdctl rm /message core@core-01 ~ $ etcdctl set /message Hello Hello core@core-01 ~ $ etcdctl get /message Titi core@core-01 ~ $ etcdctl rm /message core@core-01 ~ $ etcdctl set /message Hello Hello core@core-01 ~ $ etcdctl ls /coreos.com /first-etcd-key core@core-01 ~ $ etcdctl ls / /first-etcd-key /coreos.com core@core-01 ~ $ etcdctl ls /message Error: 100: Key not found (/message) [2977] core@core-01 ~ $ etcdctl set /message Hello Hello core@core-01 ~ $ etcdctl ls / /coreos.com /first-etcd-key /message core@core-01 ~ $ etcdctl watch /message --recursive Titi core@core-01 ~ $ etcdctl set /message "Hi" --swap-with-value "Hello" Hi core@core-01 ~ $ etcdctl set /message "Expiring Soon" --ttl 20 Expiring Soon
core@core-02 ~ $ etcdctl get /message Hello core@core-02 ~ $ etcdctl get /message Error: 100: Key not found (/message) [2830] core@core-02 ~ $ etcdctl get /message Hello core@core-02 ~ $ etcdctl set /message Titi Titi core@core-02 ~ $ etcdctl get /message Titi core@core-02 ~ $ etcdctl get /message Error: 100: Key not found (/message) [2883] core@core-02 ~ $ curl -L -X DELETE http://127.0.0.1:4001/v2/keys/message {"errorCode":100,"message":"Key not found","cause":"/message","index":2902} core@core-02 ~ $ curl -L -X DELETE http://127.0.0.1:4001/v2/keys/message {"action":"delete","node":{"key":"/message","modifiedIndex":2909,"createdIndex":2906},"prevNode":{"key":"/message","value":"Hello","modifiedIndex":2906,"createdIndex":2906}} core@core-02 ~ $ curl -L -X DELETE http://127.0.0.1:4001/v2/keys/me core@core-02 ~ $ etcdctl set /message Titi Titi core@core-02 ~ $ etcdctl set /message Titi Titi core@core-02 ~ $ etcdctl set /message Hi Hi core@core-02 ~ $ etcdctl set /message Hello Hello core@core-02 ~ $ etcdctl watch /message --recursive Hi core@core-02 ~ $ etcdctl get /message Expiring Soon core@core-02 ~ $ etcdctl get /message Expiring Soon core@core-02 ~ $ etcdctl get /message Expiring Soon core@core-02 ~ $ etcdctl get /message Expiring Soon core@core-02 ~ $ etcdctl get /message Expiring Soon core@core-02 ~ $ etcdctl get /message Error: 100: Key not found (/message) [3112]