TL;DR: Moving from etcd v2 to v3 is in general well documented, however there are a few gotchas you might wanna be aware of.
I’m ATM working on ReShifter—a tool for backing up and restoring Kubernetes clusters—and in the context of this work I came across a few things related to etcd that did cost me some cycles to sort out, so I thought I share it here to spare you the pain ;)
In general, the etcd v2 to etcd v3 migration story is well documented, see this blog post here as well as the official docs. Here are a couple of things to be aware of, both from a CLI perspective (i.e. when using etcdctl
) as well as from an API perspective (i.e. moving from the Go client lib v2 to v3):
/kubernetes.io/namespaces/kube-system -->
/kubernetes.io└──namespaces└── kube-system
discovery.Visit2()
and discovery.Visit3()
in the ReShifter code base.ETCDCTL_API=3
. This unremarkable switch causes etcdctl
to switch from talking v2 to v3. Run etcdctl
before and after setting the env variable and compare the commands you’ve got available, for example get/set
in v2 vs. get/put
in v3 (see also the screen shot at the top of this post, showing that ls
is only available in the v2 API).Let’s have a look now at a simple interaction with etcd3 and how to use the v2 and v3 API. First we launch etcd3, containerized:
$ docker run --rm -p 2379:2379 --name test-etcd \--dns 8.8.8.8 quay.io/coreos/etcd:v3.1.0 /usr/local/bin/etcd \--advertise-client-urls http://0.0.0.0:2379 \--listen-client-urls http://0.0.0.0:2379 \--listen-peer-urls http://0.0.0.0:2380
Now, let’s put a value into etcd, using the v2 API:
curl http://127.0.0.1:2379/v2/keys/kubernetes.io/namespaces/kube-system -XPUT -d value="value for v2"
Next, we switch to the v3 API:
$ export ETCDCTL_API=3
And now, we first check if we can read the value we’ve previously set using the v2 API:
$ etcdctl --endpoints=http://127.0.0.1:2379 get \/kubernetes.io/namespaces/kube-system
Which returns empty, so no way to write to the etcd2 datastore and read it out via v3. Now, let’s put something into etcd using the v3 API and query it right after it to confirm the write:
$ etcdctl --endpoints=http://127.0.0.1:2379 put \/kubernetes.io/namespaces/kube-system "value for v3"$ etcdctl --endpoints=http://127.0.0.1:2379 get \/kubernetes.io/namespaces/kube-system/kubernetes.io/namespaces/kube-systemvalue for fv3
With that I’ll wrap up this post and hope you’re successful in migrating from etcd v2 to etcd v3! If you’ve got additional insights or comments on the above, please do share them here, hit me up on Twitter (DMs are open), or come and join us on the Kubernetes Slack where I’m usually hanging out on #sig-cluster-lifecycle and #sig-apps.
Last but not least, I’d like to give Serg of CoreOS huge kudos: he patiently helped me through issues I experienced around using the v3 API. Thank you and I owe you one!