How to store binary data in etcd v3 using CLI

Viewed 1107

It's simple to extract etcd data in json(base64) or hex formats with either -w json or --hex flags

ETCDCTL_API=3 etcdctl get /registry/secrets/myns/mykey --print-value-only --hex 
ETCDCTL_API=3 etcdctl get /registry/secrets/myns/mykey -w json 

But how can one write hex/json extracted data from another etcd instance via cli? etcdctl put doesn't accept any of these parameters and will store passed value as string

1 Answers

etcd can take input from stdin, so the data can be piped in

GET the value in json(base64 encoded):

ETCDCTL_API=3 etcdctl get key -w json | jq .kvs[].value | tr -d \" > value.b64

PUT decoded value on the same/other etcd instance

base64 -D -i ./value.b64 | ETCDCTL_API=3 etcdctl put key
Related