/
README.md
1707 lines (1131 loc) · 42.6 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
etcdctl
========
`etcdctl` is a command line client for [etcd][etcd].
The v3 API is used by default on main branch. For the v2 API, make sure to set environment variable `ETCDCTL_API=2`. See also [READMEv2][READMEv2].
If using released versions earlier than v3.4, set `ETCDCTL_API=3` to use v3 API.
Global flags (e.g., `dial-timeout`, `--cacert`, `--cert`, `--key`) can be set with environment variables:
```
ETCDCTL_DIAL_TIMEOUT=3s
ETCDCTL_CACERT=/tmp/ca.pem
ETCDCTL_CERT=/tmp/cert.pem
ETCDCTL_KEY=/tmp/key.pem
```
Prefix flag strings with `ETCDCTL_`, convert all letters to upper-case, and replace dash(`-`) with underscore(`_`). Note that the environment variables with the prefix `ETCDCTL_` can only be used with the etcdctl global flags. Also, the environment variable `ETCDCTL_API` is a special case variable for etcdctl internal use only.
## Key-value commands
### PUT [options] \<key\> \<value\>
PUT assigns the specified value with the specified key. If key already holds a value, it is overwritten.
RPC: Put
#### Options
- lease -- lease ID (in hexadecimal) to attach to the key.
- prev-kv -- return the previous key-value pair before modification.
- ignore-value -- updates the key using its current value.
- ignore-lease -- updates the key using its current lease.
#### Output
`OK`
#### Examples
```bash
./etcdctl put foo bar --lease=1234abcd
# OK
./etcdctl get foo
# foo
# bar
./etcdctl put foo --ignore-value # to detache lease
# OK
```
```bash
./etcdctl put foo bar --lease=1234abcd
# OK
./etcdctl put foo bar1 --ignore-lease # to use existing lease 1234abcd
# OK
./etcdctl get foo
# foo
# bar1
```
```bash
./etcdctl put foo bar1 --prev-kv
# OK
# foo
# bar
./etcdctl get foo
# foo
# bar1
```
#### Remarks
If \<value\> isn't given as command line argument, this command tries to read the value from standard input.
When \<value\> begins with '-', \<value\> is interpreted as a flag.
Insert '--' for workaround:
```bash
./etcdctl put <key> -- <value>
./etcdctl put -- <key> <value>
```
Providing \<value\> in a new line after using `carriage return` is not supported and etcdctl may hang in that case. For example, following case is not supported:
```bash
./etcdctl put <key>\r
<value>
```
A \<value\> can have multiple lines or spaces but it must be provided with a double-quote as demonstrated below:
```bash
./etcdctl put foo "bar1 2 3"
```
### GET [options] \<key\> [range_end]
GET gets the key or a range of keys [key, range_end) if range_end is given.
RPC: Range
#### Options
- hex -- print out key and value as hex encode string
- limit -- maximum number of results
- prefix -- get keys by matching prefix
- order -- order of results; ASCEND or DESCEND
- sort-by -- sort target; CREATE, KEY, MODIFY, VALUE, or VERSION
- rev -- specify the kv revision
- print-value-only -- print only value when used with write-out=simple
- consistency -- Linearizable(l) or Serializable(s), defaults to Linearizable(l).
- from-key -- Get keys that are greater than or equal to the given key using byte compare
- keys-only -- Get only the keys
#### Output
Prints the data in format below,
```
\<key\>\n\<value\>\n\<next_key\>\n\<next_value\>...
```
Note serializable requests are better for lower latency requirement, but
stale data might be returned if serializable option (`--consistency=s`)
is specified.
#### Examples
First, populate etcd with some keys:
```bash
./etcdctl put foo bar
# OK
./etcdctl put foo1 bar1
# OK
./etcdctl put foo2 bar2
# OK
./etcdctl put foo3 bar3
# OK
```
Get the key named `foo`:
```bash
./etcdctl get foo
# foo
# bar
```
Get all keys:
```bash
./etcdctl get --from-key ''
# foo
# bar
# foo1
# bar1
# foo2
# foo2
# foo3
# bar3
```
Get all keys with names greater than or equal to `foo1`:
```bash
./etcdctl get --from-key foo1
# foo1
# bar1
# foo2
# bar2
# foo3
# bar3
```
Get keys with names greater than or equal to `foo1` and less than `foo3`:
```bash
./etcdctl get foo1 foo3
# foo1
# bar1
# foo2
# bar2
```
#### Remarks
If any key or value contains non-printable characters or control characters, simple formatted output can be ambiguous due to new lines. To resolve this issue, set `--hex` to hex encode all strings.
### DEL [options] \<key\> [range_end]
Removes the specified key or range of keys [key, range_end) if range_end is given.
RPC: DeleteRange
#### Options
- prefix -- delete keys by matching prefix
- prev-kv -- return deleted key-value pairs
- from-key -- delete keys that are greater than or equal to the given key using byte compare
#### Output
Prints the number of keys that were removed in decimal if DEL succeeded.
#### Examples
```bash
./etcdctl put foo bar
# OK
./etcdctl del foo
# 1
./etcdctl get foo
```
```bash
./etcdctl put key val
# OK
./etcdctl del --prev-kv key
# 1
# key
# val
./etcdctl get key
```
```bash
./etcdctl put a 123
# OK
./etcdctl put b 456
# OK
./etcdctl put z 789
# OK
./etcdctl del --from-key a
# 3
./etcdctl get --from-key a
```
```bash
./etcdctl put zoo val
# OK
./etcdctl put zoo1 val1
# OK
./etcdctl put zoo2 val2
# OK
./etcdctl del --prefix zoo
# 3
./etcdctl get zoo2
```
### TXN [options]
TXN reads multiple etcd requests from standard input and applies them as a single atomic transaction.
A transaction consists of list of conditions, a list of requests to apply if all the conditions are true, and a list of requests to apply if any condition is false.
RPC: Txn
#### Options
- hex -- print out keys and values as hex encoded strings.
- interactive -- input transaction with interactive prompting.
#### Input Format
```ebnf
<Txn> ::= <CMP>* "\n" <THEN> "\n" <ELSE> "\n"
<CMP> ::= (<CMPCREATE>|<CMPMOD>|<CMPVAL>|<CMPVER>|<CMPLEASE>) "\n"
<CMPOP> ::= "<" | "=" | ">"
<CMPCREATE> := ("c"|"create")"("<KEY>")" <CMPOP> <REVISION>
<CMPMOD> ::= ("m"|"mod")"("<KEY>")" <CMPOP> <REVISION>
<CMPVAL> ::= ("val"|"value")"("<KEY>")" <CMPOP> <VALUE>
<CMPVER> ::= ("ver"|"version")"("<KEY>")" <CMPOP> <VERSION>
<CMPLEASE> ::= "lease("<KEY>")" <CMPOP> <LEASE>
<THEN> ::= <OP>*
<ELSE> ::= <OP>*
<OP> ::= ((see put, get, del etcdctl command syntax)) "\n"
<KEY> ::= (%q formatted string)
<VALUE> ::= (%q formatted string)
<REVISION> ::= "\""[0-9]+"\""
<VERSION> ::= "\""[0-9]+"\""
<LEASE> ::= "\""[0-9]+\""
```
#### Output
`SUCCESS` if etcd processed the transaction success list, `FAILURE` if etcd processed the transaction failure list. Prints the output for each command in the executed request list, each separated by a blank line.
#### Examples
txn in interactive mode:
```bash
./etcdctl txn -i
# compares:
mod("key1") > "0"
# success requests (get, put, delete):
put key1 "overwrote-key1"
# failure requests (get, put, delete):
put key1 "created-key1"
put key2 "some extra key"
# FAILURE
# OK
# OK
```
txn in non-interactive mode:
```bash
./etcdctl txn <<<'mod("key1") > "0"
put key1 "overwrote-key1"
put key1 "created-key1"
put key2 "some extra key"
'
# FAILURE
# OK
# OK
```
#### Remarks
When using multi-line values within a TXN command, newlines must be represented as `\n`. Literal newlines will cause parsing failures. This differs from other commands (such as PUT) where the shell will convert literal newlines for us. For example:
```bash
./etcdctl txn <<<'mod("key1") > "0"
put key1 "overwrote-key1"
put key1 "created-key1"
put key2 "this is\na multi-line\nvalue"
'
# FAILURE
# OK
# OK
```
### COMPACTION [options] \<revision\>
COMPACTION discards all etcd event history prior to a given revision. Since etcd uses a multiversion concurrency control
model, it preserves all key updates as event history. When the event history up to some revision is no longer needed,
all superseded keys may be compacted away to reclaim storage space in the etcd backend database.
RPC: Compact
#### Options
- physical -- 'true' to wait for compaction to physically remove all old revisions
#### Output
Prints the compacted revision.
#### Example
```bash
./etcdctl compaction 1234
# compacted revision 1234
```
### WATCH [options] [key or prefix] [range_end] [--] [exec-command arg1 arg2 ...]
Watch watches events stream on keys or prefixes, [key or prefix, range_end) if range_end is given. The watch command runs until it encounters an error or is terminated by the user. If range_end is given, it must be lexicographically greater than key or "\x00".
RPC: Watch
#### Options
- hex -- print out key and value as hex encode string
- interactive -- begins an interactive watch session
- prefix -- watch on a prefix if prefix is set.
- prev-kv -- get the previous key-value pair before the event happens.
- rev -- the revision to start watching. Specifying a revision is useful for observing past events.
#### Input format
Input is only accepted for interactive mode.
```
watch [options] <key or prefix>\n
```
#### Output
\<event\>[\n\<old_key\>\n\<old_value\>]\n\<key\>\n\<value\>\n\<event\>\n\<next_key\>\n\<next_value\>\n...
#### Examples
##### Non-interactive
```bash
./etcdctl watch foo
# PUT
# foo
# bar
```
```bash
ETCDCTL_WATCH_KEY=foo ./etcdctl watch
# PUT
# foo
# bar
```
Receive events and execute `echo watch event received`:
```bash
./etcdctl watch foo -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
Watch response is set via `ETCD_WATCH_*` environmental variables:
```bash
./etcdctl watch foo -- sh -c "env | grep ETCD_WATCH_"
# PUT
# foo
# bar
# ETCD_WATCH_REVISION=11
# ETCD_WATCH_KEY="foo"
# ETCD_WATCH_EVENT_TYPE="PUT"
# ETCD_WATCH_VALUE="bar"
```
Watch with environmental variables and execute `echo watch event received`:
```bash
export ETCDCTL_WATCH_KEY=foo
./etcdctl watch -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
```bash
export ETCDCTL_WATCH_KEY=foo
export ETCDCTL_WATCH_RANGE_END=foox
./etcdctl watch -- echo watch event received
# PUT
# fob
# bar
# watch event received
```
##### Interactive
```bash
./etcdctl watch -i
watch foo
watch foo
# PUT
# foo
# bar
# PUT
# foo
# bar
```
Receive events and execute `echo watch event received`:
```bash
./etcdctl watch -i
watch foo -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
Watch with environmental variables and execute `echo watch event received`:
```bash
export ETCDCTL_WATCH_KEY=foo
./etcdctl watch -i
watch -- echo watch event received
# PUT
# foo
# bar
# watch event received
```
```bash
export ETCDCTL_WATCH_KEY=foo
export ETCDCTL_WATCH_RANGE_END=foox
./etcdctl watch -i
watch -- echo watch event received
# PUT
# fob
# bar
# watch event received
```
### LEASE \<subcommand\>
LEASE provides commands for key lease management.
### LEASE GRANT \<ttl\>
LEASE GRANT creates a fresh lease with a server-selected time-to-live in seconds
greater than or equal to the requested TTL value.
RPC: LeaseGrant
#### Output
Prints a message with the granted lease ID.
#### Example
```bash
./etcdctl lease grant 60
# lease 32695410dcc0ca06 granted with TTL(60s)
```
### LEASE REVOKE \<leaseID\>
LEASE REVOKE destroys a given lease, deleting all attached keys.
RPC: LeaseRevoke
#### Output
Prints a message indicating the lease is revoked.
#### Example
```bash
./etcdctl lease revoke 32695410dcc0ca06
# lease 32695410dcc0ca06 revoked
```
### LEASE TIMETOLIVE \<leaseID\> [options]
LEASE TIMETOLIVE retrieves the lease information with the given lease ID.
RPC: LeaseTimeToLive
#### Options
- keys -- Get keys attached to this lease
#### Output
Prints lease information.
#### Example
```bash
./etcdctl lease grant 500
# lease 2d8257079fa1bc0c granted with TTL(500s)
./etcdctl put foo1 bar --lease=2d8257079fa1bc0c
# OK
./etcdctl put foo2 bar --lease=2d8257079fa1bc0c
# OK
./etcdctl lease timetolive 2d8257079fa1bc0c
# lease 2d8257079fa1bc0c granted with TTL(500s), remaining(481s)
./etcdctl lease timetolive 2d8257079fa1bc0c --keys
# lease 2d8257079fa1bc0c granted with TTL(500s), remaining(472s), attached keys([foo2 foo1])
./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json
# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":465,"granted-ttl":500,"keys":null}
./etcdctl lease timetolive 2d8257079fa1bc0c --write-out=json --keys
# {"cluster_id":17186838941855831277,"member_id":4845372305070271874,"revision":3,"raft_term":2,"id":3279279168933706764,"ttl":459,"granted-ttl":500,"keys":["Zm9vMQ==","Zm9vMg=="]}
./etcdctl lease timetolive 2d8257079fa1bc0c
# lease 2d8257079fa1bc0c already expired
```
### LEASE LIST
LEASE LIST lists all active leases.
RPC: LeaseLeases
#### Output
Prints a message with a list of active leases.
#### Example
```bash
./etcdctl lease grant 60
# lease 32695410dcc0ca06 granted with TTL(60s)
./etcdctl lease list
32695410dcc0ca06
```
### LEASE KEEP-ALIVE \<leaseID\>
LEASE KEEP-ALIVE periodically refreshes a lease so it does not expire.
RPC: LeaseKeepAlive
#### Output
Prints a message for every keep alive sent or prints a message indicating the lease is gone.
#### Example
```bash
./etcdctl lease keep-alive 32695410dcc0ca0
# lease 32695410dcc0ca0 keepalived with TTL(100)
# lease 32695410dcc0ca0 keepalived with TTL(100)
# lease 32695410dcc0ca0 keepalived with TTL(100)
...
```
## Cluster maintenance commands
### MEMBER \<subcommand\>
MEMBER provides commands for managing etcd cluster membership.
### MEMBER ADD \<memberName\> [options]
MEMBER ADD introduces a new member into the etcd cluster as a new peer.
RPC: MemberAdd
#### Options
- peer-urls -- comma separated list of URLs to associate with the new member.
#### Output
Prints the member ID of the new member and the cluster ID.
#### Example
```bash
./etcdctl member add newMember --peer-urls=https://127.0.0.1:12345
Member ced000fda4d05edf added to cluster 8c4281cc65c7b112
ETCD_NAME="newMember"
ETCD_INITIAL_CLUSTER="newMember=https://127.0.0.1:12345,default=http://10.0.0.30:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"
```
### MEMBER UPDATE \<memberID\> [options]
MEMBER UPDATE sets the peer URLs for an existing member in the etcd cluster.
RPC: MemberUpdate
#### Options
- peer-urls -- comma separated list of URLs to associate with the updated member.
#### Output
Prints the member ID of the updated member and the cluster ID.
#### Example
```bash
./etcdctl member update 2be1eb8f84b7f63e --peer-urls=https://127.0.0.1:11112
# Member 2be1eb8f84b7f63e updated in cluster ef37ad9dc622a7c4
```
### MEMBER REMOVE \<memberID\>
MEMBER REMOVE removes a member of an etcd cluster from participating in cluster consensus.
RPC: MemberRemove
#### Output
Prints the member ID of the removed member and the cluster ID.
#### Example
```bash
./etcdctl member remove 2be1eb8f84b7f63e
# Member 2be1eb8f84b7f63e removed from cluster ef37ad9dc622a7c4
```
### MEMBER LIST
MEMBER LIST prints the member details for all members associated with an etcd cluster.
RPC: MemberList
#### Options
- consistency -- Linearizable(l) or Serializable(s), defaults to Linearizable(l).
#### Output
Prints a humanized table of the member IDs, statuses, names, peer addresses, and client addresses.
Note serializable requests are better for lower latency requirement, but
stale member list might be returned if serializable option (`--consistency=s`)
is specified. In some situations users may want to use serializable requests.
For example, when adding a new member to a one-node cluster, it's reasonable
and safe to use serializable request before the new added member gets started.
#### Examples
```bash
./etcdctl member list
# 8211f1d0f64f3269, started, infra1, http://127.0.0.1:12380, http://127.0.0.1:2379
# 91bc3c398fb3c146, started, infra2, http://127.0.0.1:22380, http://127.0.0.1:22379
# fd422379fda50e48, started, infra3, http://127.0.0.1:32380, http://127.0.0.1:32379
```
```bash
./etcdctl -w json member list
# {"header":{"cluster_id":17237436991929493444,"member_id":9372538179322589801,"raft_term":2},"members":[{"ID":9372538179322589801,"name":"infra1","peerURLs":["http://127.0.0.1:12380"],"clientURLs":["http://127.0.0.1:2379"]},{"ID":10501334649042878790,"name":"infra2","peerURLs":["http://127.0.0.1:22380"],"clientURLs":["http://127.0.0.1:22379"]},{"ID":18249187646912138824,"name":"infra3","peerURLs":["http://127.0.0.1:32380"],"clientURLs":["http://127.0.0.1:32379"]}]}
```
```bash
./etcdctl -w table member list
+------------------+---------+--------+------------------------+------------------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS |
+------------------+---------+--------+------------------------+------------------------+
| 8211f1d0f64f3269 | started | infra1 | http://127.0.0.1:12380 | http://127.0.0.1:2379 |
| 91bc3c398fb3c146 | started | infra2 | http://127.0.0.1:22380 | http://127.0.0.1:22379 |
| fd422379fda50e48 | started | infra3 | http://127.0.0.1:32380 | http://127.0.0.1:32379 |
+------------------+---------+--------+------------------------+------------------------+
```
### ENDPOINT \<subcommand\>
ENDPOINT provides commands for querying individual endpoints.
#### Options
- cluster -- fetch and use all endpoints from the etcd cluster member list
### ENDPOINT HEALTH
ENDPOINT HEALTH checks the health of the list of endpoints with respect to cluster. An endpoint is unhealthy
when it cannot participate in consensus with the rest of the cluster.
#### Output
If an endpoint can participate in consensus, prints a message indicating the endpoint is healthy. If an endpoint fails to participate in consensus, prints a message indicating the endpoint is unhealthy.
#### Example
Check the default endpoint's health:
```bash
./etcdctl endpoint health
# 127.0.0.1:2379 is healthy: successfully committed proposal: took = 2.095242ms
```
Check all endpoints for the cluster associated with the default endpoint:
```bash
./etcdctl endpoint --cluster health
# http://127.0.0.1:2379 is healthy: successfully committed proposal: took = 1.060091ms
# http://127.0.0.1:22379 is healthy: successfully committed proposal: took = 903.138µs
# http://127.0.0.1:32379 is healthy: successfully committed proposal: took = 1.113848ms
```
### ENDPOINT STATUS
ENDPOINT STATUS queries the status of each endpoint in the given endpoint list.
#### Output
##### Simple format
Prints a humanized table of each endpoint URL, ID, version, database size, leadership status, raft term, and raft status.
##### JSON format
Prints a line of JSON encoding each endpoint URL, ID, version, database size, leadership status, raft term, and raft status.
#### Examples
Get the status for the default endpoint:
```bash
./etcdctl endpoint status
# 127.0.0.1:2379, 8211f1d0f64f3269, 3.0.0, 25 kB, false, 2, 63
```
Get the status for the default endpoint as JSON:
```bash
./etcdctl -w json endpoint status
# [{"Endpoint":"127.0.0.1:2379","Status":{"header":{"cluster_id":17237436991929493444,"member_id":9372538179322589801,"revision":2,"raft_term":2},"version":"3.0.0","dbSize":24576,"leader":18249187646912138824,"raftIndex":32623,"raftTerm":2}}]
```
Get the status for all endpoints in the cluster associated with the default endpoint:
```bash
./etcdctl -w table endpoint --cluster status
+------------------------+------------------+---------------+-----------------+---------+----------------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | STORAGE VERSION | DB SIZE | DB SIZE IN USE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------+------------------+---------------+-----------------+---------+----------------+-----------+------------+-----------+------------+--------------------+--------+
| http://127.0.0.1:2379 | 8211f1d0f64f3269 | 3.6.0-alpha.0 | 3.6.0 | 25 kB | 25 kB | false | false | 2 | 8 | 8 | |
| http://127.0.0.1:22379 | 91bc3c398fb3c146 | 3.6.0-alpha.0 | 3.6.0 | 25 kB | 25 kB | true | false | 2 | 8 | 8 | |
| http://127.0.0.1:32379 | fd422379fda50e48 | 3.6.0-alpha.0 | 3.6.0 | 25 kB | 25 kB | false | false | 2 | 8 | 8 | |
+------------------------+------------------+---------------+-----------------+---------+----------------+-----------+------------+-----------+------------+--------------------+--------+
```
### ENDPOINT HASHKV
ENDPOINT HASHKV fetches the hash of the key-value store of an endpoint.
#### Output
##### Simple format
Prints a humanized table of each endpoint URL and KV history hash.
##### JSON format
Prints a line of JSON encoding each endpoint URL and KV history hash.
#### Examples
Get the hash for the default endpoint:
```bash
./etcdctl endpoint hashkv --cluster
http://127.0.0.1:2379, 2064120424, 13
http://127.0.0.1:22379, 2064120424, 13
http://127.0.0.1:32379, 2064120424, 13
```
Get the status for the default endpoint as JSON:
```bash
./etcdctl endpoint hash --cluster -w json | jq
[
{
"Endpoint": "http://127.0.0.1:2379",
"HashKV": {
"header": {
"cluster_id": 17237436991929494000,
"member_id": 9372538179322590000,
"revision": 13,
"raft_term": 2
},
"hash": 2064120424,
"compact_revision": -1,
"hash_revision": 13
}
},
{
"Endpoint": "http://127.0.0.1:22379",
"HashKV": {
"header": {
"cluster_id": 17237436991929494000,
"member_id": 10501334649042878000,
"revision": 13,
"raft_term": 2
},
"hash": 2064120424,
"compact_revision": -1,
"hash_revision": 13
}
},
{
"Endpoint": "http://127.0.0.1:32379",
"HashKV": {
"header": {
"cluster_id": 17237436991929494000,
"member_id": 18249187646912140000,
"revision": 13,
"raft_term": 2
},
"hash": 2064120424,
"compact_revision": -1,
"hash_revision": 13
}
}
]
```
Get the status for all endpoints in the cluster associated with the default endpoint:
```bash
$ ./etcdctl endpoint hash --cluster -w table
+------------------------+-----------+---------------+
| ENDPOINT | HASH | HASH REVISION |
+------------------------+-----------+---------------+
| http://127.0.0.1:2379 | 784522900 | 16 |
| http://127.0.0.1:22379 | 784522900 | 16 |
| http://127.0.0.1:32379 | 784522900 | 16 |
+------------------------+-----------+---------------+
```
### ALARM \<subcommand\>
Provides alarm related commands
### ALARM DISARM
`alarm disarm` Disarms all alarms
RPC: Alarm
#### Output
`alarm:<alarm type>` if alarm is present and disarmed.
#### Examples
```bash
./etcdctl alarm disarm
```
If NOSPACE alarm is present:
```bash
./etcdctl alarm disarm
# alarm:NOSPACE
```
### ALARM LIST
`alarm list` lists all alarms.
RPC: Alarm
#### Output
`alarm:<alarm type>` if alarm is present, empty string if no alarms present.
#### Examples
```bash
./etcdctl alarm list
```
If NOSPACE alarm is present:
```bash
./etcdctl alarm list
# alarm:NOSPACE
```
### DEFRAG [options]
DEFRAG defragments the backend database file for a set of given endpoints while etcd is running. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system.
**Note: to defragment offline (`--data-dir` flag), use: `etcutl defrag` instead**
**Note that defragmentation to a live member blocks the system from reading and writing data while rebuilding its states.**
**Note that defragmentation request does not get replicated over cluster. That is, the request is only applied to the local node. Specify all members in `--endpoints` flag or `--cluster` flag to automatically find all cluster members.**
#### Output
For each endpoints, prints a message indicating whether the endpoint was successfully defragmented.
#### Example
```bash
./etcdctl --endpoints=localhost:2379,badendpoint:2379 defrag
# Finished defragmenting etcd member[localhost:2379]
# Failed to defragment etcd member[badendpoint:2379] (grpc: timed out trying to connect)
```
Run defragment operations for all endpoints in the cluster associated with the default endpoint:
```bash