从 etcd 读取数据

在 etcd 集群中读取值

前提条件

  • 安装 etcdctl

步骤

使用 get 子命令从 etcd 中读取数据:

$ etcdctl --endpoints=$ENDPOINTS get foo
foo
Hello World!
$

其中:

  • foo 是请求的键
  • Hello World! 是检索到的值

或者,对于格式化的输出:

$ etcdctl --endpoints=$ENDPOINTS --write-out="json" get foo
{"header":{"cluster_id":289318470931837780,"member_id":14947050114012957595,"revision":3,"raft_term":4,
"kvs":[{"key":"Zm9v","create_revision":2,"mod_revision":3,"version":2,"value":"SGVsbG8gV29ybGQh"}]}}
$

其中 write-out="json" 使值以 JSON 格式输出(请注意,键不会被返回)。


最后修改于 2025 年 7 月 6 日: etcd-网站: 重组 v3.7 (c159c16)