Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need to put ETCDCTL_API=3 in front of etcdctl for etcdctl snapshot save to work?

I did a customized installation of Kubernetes the hardway and installed it successfully on a 2 node cluster in Hyper V (1 master 1 worker), everything works, but there's this thing that makes me scratch my head and I was wondering if anyone could give me insight about why it's happening.

etcdctl --help

Gives me the etcd v2 version of the help, and it also gives me the following Warning.

WARNING: Environment variable ETCDCTL_API is not set; defaults to etcdctl v2. Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API.

If I set the environment variable and run the command again, it's ignored:

ETCDCTL_API=3
etcdctl --help

But if I do

ETCDCTL_API=3 etcdctl --help

Then it gives me the etcd v3 version of the help, I also need to put ETCDCTL_API=3 in front of etcdctl snapshot save for it to be recognized as a valid command.

ETCDCTL_API=3 etcdctl snapshot save ~/etcd.backup \
  --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/etcd/ca.pem \
  --cert=/etc/etcd/kubernetes.pem \
  --key=/etc/etcd/kubernetes-key.pem

Why is this?

like image 741
neokyle Avatar asked Oct 08 '18 04:10

neokyle


2 Answers

Well it turned out to be a lack of Linux knowledge. When I was following a few Kubernetes how to guides I used Bash variables all the time, what I didn't realize is that there's a difference between normal variables an environment variables.

I was doing:

ETCDCTL_API=3 
echo $ETCDCTL_API
3

And it looked right, but then I remembered the printenv command, and I didn't see what I expected, that's when I figured out there was a difference between environment variables and regular variables.

I had to add export in front of the variable statement, to make it an environment variable.

What's really cool is that after reading this
https://github.com/etcd-io/etcd/blob/master/etcdctl/README.md

I was able to make the above, become nice short commands like this:

export ETCDCTL_API=3
export ETCDCTL_CACERT=/etc/etcd/ca.pem
export ETCDCTL_CERT=/etc/etcd/kubernetes.pem
export ETCDCTL_KEY=/etc/etcd/kubernetes-key.pem

etcdctl member list --endpoints=https://127.0.0.1:2379 

etcdctl snapshot save ~/etcd.backup
like image 70
neokyle Avatar answered Nov 09 '22 09:11

neokyle


It's no longer needed since etcd 3.4: https://github.com/etcd-io/etcd/pull/9784

like image 39
B.Z. Avatar answered Nov 09 '22 09:11

B.Z.