etcd v3 can't read encoded values

8/17/2017

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
etcd
etcd3
kubernetes

3 Answers

8/14/2019

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
Source: StackOverflow

11/1/2018

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.

-- Bo Wang
Source: StackOverflow

8/18/2017

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

-- Jordan Liggitt
Source: StackOverflow