Skip to content

Instantly share code, notes, and snippets.

@binarytemple
Last active January 15, 2016 11:37
Show Gist options
  • Save binarytemple/c252469f76d537472080 to your computer and use it in GitHub Desktop.
Save binarytemple/c252469f76d537472080 to your computer and use it in GitHub Desktop.

etcd is configured to only listen on certain interfaces - set the interface IP address.

IF=$(ip addr show eth0 | sed -n '/inet /{s_[^1-9]*__;s_/.*__;p}')

By default etcd is configured to listen on port 2379 for client communication and on port 2380 for server-to-server communication.

curl -L http://${IF}:2379/version
{"etcdserver":"2.2.3","etcdcluster":"2.2.0"}%
curl -L http://${IF}:2379/v2/keys/message -XPUT -d value="foo"
{"action":"set","node":{"key":"/message","value":"foo","modifiedIndex":4,"createdIndex":4}}
curl -L http://${IF}:2379/v2/keys/message
{"action":"get","node":{"key":"/message","value":"foo","modifiedIndex":4,"createdIndex":4}}
curl -v -L http://${IF}:2379/v2/keys/message
*   Trying 172.16.186.132...
* Connected to 172.16.186.132 (172.16.186.132) port 2379 (#0)
> GET /v2/keys/message HTTP/1.1
> Host: 172.16.186.132:2379
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< X-Etcd-Cluster-Id: 7e27652122e8b2ae
< X-Etcd-Index: 4
< X-Raft-Index: 1433
< X-Raft-Term: 2
< Date: Wed, 13 Jan 2016 17:18:46 GMT
< Content-Length: 92
<
{"action":"get","node":{"key":"/message","value":"foo","modifiedIndex":4,"createdIndex":4}}
* Connection #0 to host 172.16.186.132 left intact
curl -v -L http://${IF}:2379/v2/keys/message
*   Trying 172.16.186.132...
* Connected to 172.16.186.132 (172.16.186.132) port 2379 (#0)
> GET /v2/keys/message HTTP/1.1
> Host: 172.16.186.132:2379
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< X-Etcd-Cluster-Id: 7e27652122e8b2ae
< X-Etcd-Index: 4
< X-Raft-Index: 1488
< X-Raft-Term: 2
< Date: Wed, 13 Jan 2016 17:19:14 GMT
< Content-Length: 92
<
{"action":"get","node":{"key":"/message","value":"foo","modifiedIndex":4,"createdIndex":4}}
* Connection #0 to host 172.16.186.132 left intact
curl -L http://${IF}:2379/v2/keys/message -XPUT -d value="food"
{"action":"set","node":{"key":"/message","value":"food","modifiedIndex":5,"createdIndex":5},"prevNode":{"key":"/message","value":"foo","modifiedIndex":4,"createdIndex":4}}
curl -v -L http://${IF}:2379/v2/keys/message
*   Trying 172.16.186.132...
* Connected to 172.16.186.132 (172.16.186.132) port 2379 (#0)
> GET /v2/keys/message HTTP/1.1
> Host: 172.16.186.132:2379
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< X-Etcd-Cluster-Id: 7e27652122e8b2ae
< X-Etcd-Index: 5
< X-Raft-Index: 1506
< X-Raft-Term: 2
< Date: Wed, 13 Jan 2016 17:19:22 GMT
< Content-Length: 93
<
{"action":"get","node":{"key":"/message","value":"food","modifiedIndex":5,"createdIndex":5}}
* Connection #0 to host 172.16.186.132 left intact
curl -L http://127.0.0.1:2379/v2/keys/message -XDELETE
curl: (7) Failed to connect to 127.0.0.1 port 2379: Connection refused
curl -L http://${IF}:2379/v2/keys/message -XDELETE
{"action":"delete","node":{"key":"/message","modifiedIndex":6,"createdIndex":5},"prevNode":{"key":"/message","value":"food","modifiedIndex":5,"createdIndex":5}}
curl -v -L http://${IF}:2379/v2/keys/message
*   Trying 172.16.186.132...
* Connected to 172.16.186.132 (172.16.186.132) port 2379 (#0)
> GET /v2/keys/message HTTP/1.1
> Host: 172.16.186.132:2379
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json
< X-Etcd-Cluster-Id: 7e27652122e8b2ae
< X-Etcd-Index: 6
< Date: Wed, 13 Jan 2016 17:20:05 GMT
< Content-Length: 73
<
{"errorCode":100,"message":"Key not found","cause":"/message","index":6}
* Connection #0 to host 172.16.186.132 left intact
curl -L http://${IF}:2379/v2/keys/
{"action":"get","node":{"dir":true}}
curl -L http://${IF}:2379/v2/keys/message -XPUT -d value="food"
{"action":"set","node":{"key":"/message","value":"food","modifiedIndex":7,"createdIndex":7}}
curl -L http://${IF}:2379/v2/keys/
{"action":"get","node":{"dir":true,"nodes":[{"key":"/message","value":"food","modifiedIndex":7,"createdIndex":7}]}}
curl -L http://${IF}:2379/v2/keys/_message -XPUT -d value="food"
{"action":"set","node":{"key":"/_message","value":"food","modifiedIndex":8,"createdIndex":8}}
curl -L http://${IF}:2379/v2/keys/
{"action":"get","node":{"dir":true,"nodes":[{"key":"/message","value":"food","modifiedIndex":7,"createdIndex":7}]}}
curl -L http://${IF}:2379/v2/keys/_message
{"action":"get","node":{"key":"/_message","value":"food","modifiedIndex":8,"createdIndex":8}}

curl -L http://${IF}:2379/v2/keys/foo_dir/message -XPUT -d value="food"
{"action":"set","node":{"key":"/foo_dir/message","value":"food","modifiedIndex":9,"createdIndex":9}}
curl -L http://${IF}:2379/v2/keys/
{"action":"get","node":{"dir":true,"nodes":[{"key":"/message","value":"food","modifiedIndex":7,"createdIndex":7},{"key":"/foo_dir","dir":true,"modifiedIndex":9,"createdIndex":9}]}}
curl -L http://${IF}:2379/v2/keys/foo_dir
{"action":"get","node":{"key":"/foo_dir","dir":true,"nodes":[{"key":"/foo_dir/message","value":"food","modifiedIndex":9,"createdIndex":9}],"modifiedIndex":9,"createdIndex":9}}
curl -L http://${IF}:2379/v2/admin/machines
404 page not found
curl -L http://${IF}:2379/admin/machines
404 page not found
curl -L http://${IF}:2379/admin
404 page not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment