|
1 |
| -etcdctl |
2 |
| -======== |
3 |
| - |
4 |
| -[](https://travis-ci.org/coreos/etcdctl) |
5 |
| - |
6 |
| -`etcdctl` is a command line client for [etcd][etcd]. |
7 |
| -It can be used in scripts or for administrators to explore an etcd cluster. |
8 |
| - |
9 |
| -[etcd]: https://github.com/coreos/etcd |
10 |
| - |
11 |
| - |
12 |
| -## Getting etcdctl |
13 |
| - |
14 |
| -The latest release is available as a binary at [Github][github-release] along with etcd. |
15 |
| - |
16 |
| -[github-release]: https://github.com/coreos/etcd/releases/ |
17 |
| - |
18 |
| -You can also build etcdctl from source: |
19 |
| - |
20 |
| -``` |
21 |
| -./build |
22 |
| -``` |
23 |
| - |
24 |
| - |
25 |
| -## Usage |
26 |
| - |
27 |
| -### Setting Key Values |
28 |
| - |
29 |
| -Set a value on the `/foo/bar` key: |
30 |
| - |
31 |
| -``` |
32 |
| -$ etcdctl set /foo/bar "Hello world" |
33 |
| -Hello world |
34 |
| -``` |
35 |
| - |
36 |
| -Set a value on the `/foo/bar` key with a value that expires in 60 seconds: |
37 |
| - |
38 |
| -``` |
39 |
| -$ etcdctl set /foo/bar "Hello world" --ttl 60 |
40 |
| -Hello world |
41 |
| -``` |
42 |
| - |
43 |
| -Conditionally set a value on `/foo/bar` if the previous value was "Hello world": |
44 |
| - |
45 |
| -``` |
46 |
| -$ etcdctl set /foo/bar "Goodbye world" --swap-with-value "Hello world" |
47 |
| -Goodbye world |
48 |
| -``` |
49 |
| - |
50 |
| -Conditionally set a value on `/foo/bar` if the previous etcd index was 12: |
51 |
| - |
52 |
| -``` |
53 |
| -$ etcdctl set /foo/bar "Goodbye world" --swap-with-index 12 |
54 |
| -Goodbye world |
55 |
| -``` |
56 |
| - |
57 |
| -Create a new key `/foo/bar`, only if the key did not previously exist: |
58 |
| - |
59 |
| -``` |
60 |
| -$ etcdctl mk /foo/new_bar "Hello world" |
61 |
| -Hello world |
62 |
| -``` |
63 |
| - |
64 |
| -Create a new dir `/fooDir`, only if the key did not previously exist: |
65 |
| - |
66 |
| -``` |
67 |
| -$ etcdctl mkdir /fooDir |
68 |
| -``` |
69 |
| - |
70 |
| -Update an existing key `/foo/bar`, only if the key already existed: |
71 |
| - |
72 |
| -``` |
73 |
| -$ etcdctl update /foo/bar "Hola mundo" |
74 |
| -Hola mundo |
75 |
| -``` |
76 |
| - |
77 |
| -Create or update a directory called `/mydir`: |
78 |
| - |
79 |
| -``` |
80 |
| -$ etcdctl setDir /mydir |
81 |
| -``` |
82 |
| - |
83 |
| - |
84 |
| -### Retrieving a key value |
85 |
| - |
86 |
| -Get the current value for a single key in the local etcd node: |
87 |
| - |
88 |
| -``` |
89 |
| -$ etcdctl get /foo/bar |
90 |
| -Hello world |
91 |
| -``` |
92 |
| - |
93 |
| -Get the current value for a key within the cluster: |
94 |
| - |
95 |
| -``` |
96 |
| -$ etcdctl get /foo/bar --consistent |
97 |
| -Hello world |
98 |
| -``` |
99 |
| - |
100 |
| -Get the value of a key with additional metadata in a parseable format: |
101 |
| - |
102 |
| -``` |
103 |
| -$ etcdctl -o extended get /foo/bar |
104 |
| -Key: /foo/bar |
105 |
| -Modified-Index: 72 |
106 |
| -TTL: 0 |
107 |
| -Etcd-Index: 72 |
108 |
| -Raft-Index: 5611 |
109 |
| -Raft-Term: 1 |
110 |
| -
|
111 |
| -Hello World |
112 |
| -``` |
113 |
| - |
114 |
| -### Listing a directory |
115 |
| - |
116 |
| -Explore the keyspace using the `ls` command |
117 |
| - |
118 |
| -``` |
119 |
| -$ etcdctl ls |
120 |
| -/akey |
121 |
| -/adir |
122 |
| -$ etcdctl ls /adir |
123 |
| -/adir/key1 |
124 |
| -/adir/key2 |
125 |
| -``` |
126 |
| - |
127 |
| -Add `--recursive` to recursively list subdirectories encountered. |
128 |
| - |
129 |
| -``` |
130 |
| -$ etcdctl ls --recursive |
131 |
| -/akey |
132 |
| -/adir |
133 |
| -/adir/key1 |
134 |
| -/adir/key2 |
135 |
| -``` |
136 |
| - |
137 |
| -Directories can also have a trailing `/` added to output using `-p`. |
138 |
| - |
139 |
| -``` |
140 |
| -$ etcdctl ls -p |
141 |
| -/akey |
142 |
| -/adir/ |
143 |
| -``` |
144 |
| - |
145 |
| -### Deleting a key |
146 |
| - |
147 |
| -Delete a key: |
148 |
| - |
149 |
| -``` |
150 |
| -$ etcdctl rm /foo/bar |
151 |
| -``` |
152 |
| - |
153 |
| -Delete an empty directory or a key-value pair |
154 |
| - |
155 |
| -``` |
156 |
| -$ etcdctl rmdir /path/to/dir |
157 |
| -``` |
158 |
| - |
159 |
| -or |
160 |
| - |
161 |
| -``` |
162 |
| -$ etcdctl rm /path/to/dir --dir |
163 |
| -``` |
164 |
| - |
165 |
| -Recursively delete a key and all child keys: |
166 |
| - |
167 |
| -``` |
168 |
| -$ etcdctl rm /path/to/dir --recursive |
169 |
| -``` |
170 |
| - |
171 |
| -Conditionally delete `/foo/bar` if the previous value was "Hello world": |
172 |
| - |
173 |
| -``` |
174 |
| -$ etcdctl rm /foo/bar --with-value "Hello world" |
175 |
| -``` |
176 |
| - |
177 |
| -Conditionally delete `/foo/bar` if the previous etcd index was 12: |
178 |
| - |
179 |
| -``` |
180 |
| -$ etcdctl rm /foo/bar --with-index 12 |
181 |
| -``` |
182 |
| - |
183 |
| -### Watching for changes |
184 |
| - |
185 |
| -Watch for only the next change on a key: |
186 |
| - |
187 |
| -``` |
188 |
| -$ etcdctl watch /foo/bar |
189 |
| -Hello world |
190 |
| -``` |
191 |
| - |
192 |
| -Continuously watch a key: |
193 |
| - |
194 |
| -``` |
195 |
| -$ etcdctl watch /foo/bar --forever |
196 |
| -Hello world |
197 |
| -.... client hangs forever until ctrl+C printing values as key change |
198 |
| -``` |
199 |
| - |
200 |
| -Continuously watch a key, starting with a given etcd index: |
201 |
| - |
202 |
| -``` |
203 |
| -$ etcdctl watch /foo/bar --forever --index 12 |
204 |
| -Hello world |
205 |
| -.... client hangs forever until ctrl+C printing values as key change |
206 |
| -``` |
207 |
| - |
208 |
| -Continuously watch a key and exec a program: |
209 |
| - |
210 |
| -``` |
211 |
| -$ etcdctl exec-watch /foo/bar -- sh -c "env | grep ETCD" |
212 |
| -ETCD_WATCH_ACTION=set |
213 |
| -ETCD_VALUE=My configuration stuff |
214 |
| -ETCD_MODIFIED_INDEX=1999 |
215 |
| -ETCD_KEY=/foo/bar |
216 |
| -ETCD_WATCH_ACTION=set |
217 |
| -ETCD_VALUE=My new configuration stuff |
218 |
| -ETCD_MODIFIED_INDEX=2000 |
219 |
| -ETCD_KEY=/foo/bar |
220 |
| -``` |
221 |
| - |
222 |
| -Continuously and recursively watch a key and exec a program: |
223 |
| -``` |
224 |
| -$ etcdctl exec-watch --recursive /foo -- sh -c "env | grep ETCD" |
225 |
| -ETCD_WATCH_ACTION=set |
226 |
| -ETCD_VALUE=My configuration stuff |
227 |
| -ETCD_MODIFIED_INDEX=1999 |
228 |
| -ETCD_KEY=/foo/bar |
229 |
| -ETCD_WATCH_ACTION=set |
230 |
| -ETCD_VALUE=My new configuration stuff |
231 |
| -ETCD_MODIFIED_INDEX=2000 |
232 |
| -ETCD_KEY=/foo/barbar |
233 |
| -``` |
234 |
| - |
235 |
| -## Return Codes |
236 |
| - |
237 |
| -The following exit codes can be returned from etcdctl: |
238 |
| - |
239 |
| -``` |
240 |
| -0 Success |
241 |
| -1 Malformed etcdctl arguments |
242 |
| -2 Failed to connect to host |
243 |
| -3 Failed to auth (client cert rejected, ca validation failure, etc) |
244 |
| -4 400 error from etcd |
245 |
| -5 500 error from etcd |
246 |
| -``` |
247 |
| - |
248 |
| -## Peers |
249 |
| - |
250 |
| -If your etcd cluster isn't available on `http://127.0.0.1:4001` you can specify |
251 |
| -a `--peers` flag or `ETCDCTL_PEERS` environment variable. You can list one peer, |
252 |
| -or a comma-separated list of peers. |
253 |
| - |
254 |
| -``` |
255 |
| -ETCDCTL_PEERS="http://10.0.28.1:4002" etcdctl set my-key to-a-value |
256 |
| -ETCDCTL_PEERS="http://10.0.28.1:4002,http://10.0.28.2:4002,http://10.0.28.3:4002" etcdctl set my-key to-a-value |
257 |
| -etcdctl --peers http://10.0.28.1:4002 my-key to-a-value |
258 |
| -etcdctl --peers http://10.0.28.1:4002,http://10.0.28.2:4002,http://10.0.28.3:4002 etcdctl set my-key to-a-value |
259 |
| -``` |
260 |
| - |
261 |
| -## Project Details |
262 |
| - |
263 |
| -### Versioning |
264 |
| - |
265 |
| -etcdctl uses [semantic versioning][semver]. |
266 |
| -Releases will follow lockstep with the etcd release cycle. |
267 |
| - |
268 |
| -[semver]: http://semver.org/ |
269 |
| - |
270 |
| -### License |
271 |
| - |
272 |
| -etcdctl is under the Apache 2.0 license. See the [LICENSE][license] file for details. |
273 |
| - |
274 |
| -[license]: https://github.com/coreos/etcdctl/blob/master/LICENSE |
| 1 | +This tool has moved to [github.com/coreos/etcd/etcdctl](https://github.com/coreos/etcd/tree/master/etcdctl). |
0 commit comments