3

I'm trying to retrieve values from etcd v3 in a kubernetes cluster. The values appear to be encoded and don't come back complete. When -w simple, the value comes back with a lot of question marks in little diamonds. When using -w json, the value comes back like this:

ubuntu@k8s-master-0:~$ etcdctl --endpoints=https://127.0.0.1:2379 -w json get /registry/services/specs/default/kubernetes-bootcamp
{"header":{"cluster_id":13533136872321707204,"member_id":12171258639343793897,"revision":1142056,"raft_term":53},"kvs":[{"key":"L3JlZ2lzdHJ5L3NlcnZpY2VzL3NwZWNzL2RlZmF1bHQva3ViZXJuZXRlcy1ib290Y2FtcA==","create_revision":863556,"mod_revision":863556,"version":1,"value":"azhzAAoNCgJ2MRIHU2VydmljZRLaAQp3ChNrdWJlcm5ldGVzLWJvb3RjYW1wEgAaB2RlZmF1bHQiACokNzBhNDdlZDgtODFjZS0xMWU3LWE2ZGMtZmExNjNlYmZlNzM5MgA4AEILCLOmzMwFEOaHwTdaGgoDcnVuEhNrdWJlcm5ldGVzLWJvb3RjYW1wegASWwoXCgASA1RDUBiYPyIHCAAQkD8aACjR+QESGgoDcnVuEhNrdWJlcm5ldGVzLWJvb3RjYW1wGgwxMC4yMzMuNTIuNzEiDExvYWRCYWxhbmNlcjoETm9uZUIAUgAaAgoAGgAiAA=="}],"count":1}

The key and value appear to be encoded, but I can't find a way to get the plain text value back.

How can I get the plain text value for a given key?

Daniel Watrous
  • 3,467
  • 2
  • 36
  • 48
  • 1
    The key above is base64 encoded and can be directly decoded. The value above appears to be base64 encoded, but it decodes only partially into regular characters with special characters throughout. – Daniel Watrous Aug 18 '17 at 14:23

3 Answers3

4

A bit late to the show but here is how I was able to do that. Because in etcd pre-v3 the data was stored in plain json and since v3 it is in binary format the additional decode step is needed.

You may check this repo for details: https://github.com/jpbetz/auger

And here are Kubernetes docs regarding protobuf encoding

And the working example is:

etcdctl get "/registry/pods/default/nginx-dbddb74b8-62hh7" --prefix -w simple | auger decode

Now the response is plain-text:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubernetes.io/limit-ranger: 'LimitRanger plugin set: cpu request for container
      nginx'
  creationTimestamp: 2019-08-12T14:11:57Z
...
esboych
  • 985
  • 2
  • 10
  • 16
0

By default in kube 1.6 and up, values are stored in protobuf encoding, not JSON

Jordan Liggitt
  • 16,933
  • 2
  • 56
  • 44
  • The key and value in the above output look more like base64 output than protobuf, so I'm not sure how to decode them. How can I convert the protobuf format to something readable (by human or script)? – Daniel Watrous Aug 18 '17 at 14:07
0

kubernetes known issue:https://github.com/kubernetes/kubernetes/issues/44670

As mentioned in the issue,the openshift tool(https://github.com/openshift/origin/tree/master/tools/etcdhelper) could help read the value. It works for me, but it's really not convenient.

chestack
  • 71
  • 7