Skip to content

Instantly share code, notes, and snippets.

@nevermosby
Last active August 28, 2019 09:11
Show Gist options
  • Select an option

  • Save nevermosby/f474b07117f3256c5cf4b628c8f4550a to your computer and use it in GitHub Desktop.

Select an option

Save nevermosby/f474b07117f3256c5cf4b628c8f4550a to your computer and use it in GitHub Desktop.
etcdctl-mannual

use etcdctl for etcd v3 API

if you have access to the etcd server, you can use the following steps to try etcd v3 API to fetch Kubernetes cluster data

  1. set environment to use v3 API
# set ETCDCTL_API
export ETCDCTL_API=3
  1. use etcdctl tool to fetch all the namespaces
# fetch all the namespaces
etcd get /registry/namespaces --prefix -w json | jq .
# as the key and value stored in etcd have been base64-encoded, you need to decode it if you want to know what exactly they are.
etcd get /registry/namespaces --prefix -w json | jq . 'kvs[] | .value' | tr -d \" | base64 -d
  1. use etcdctl tool to fetch all the events

  2. use etcdctl too to fetch all the metadata structure

keys=`etcdctl get /registry --prefix -w json|python -m json.tool|grep key|cut -d ":" -f2|tr -d '"'|tr -d ","`
for x in $keys;do
  echo $x|base64 -d|sort
done
  1. get all keys via v3 api
etcdctl get "" --prefix --keys-only # u will get blank lines

etcdctl get "" --prefix --keys-only | sed '/^\s*$/d' # u will get keys without blanklines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment