ETCD Backup and Restore Issue

saip:
Seems like with etcdctl 3.4.3 there is no need to specify ETCDCTL_API=3 parameter ? I instantiated a 1.18 cluster with kubeadm and the etcd pod does not accept any of the commands that starts with ETCDCTL_API=3 ?

saip:
k8s-master:~ kubectl -n kube-system exec etcd-k8s-master -- etcdctl version etcdctl version: 3.4.3 API version: 3.4 k8s-master:~ kubectl -n kube-system exec -it etcd-k8s-master – ETCDCTL_API=3 etcdctl --help
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused “exec: \“ETCDCTL_API=3\“: executable file not found in PATH”: unknown command terminated with exit code 126 k8s-master:~

saip:
Any thoughts ?

Kratik Jain:
It’s not like you don’t need to specify ETCDCTL_API=3
Afaik and Whatever the examples I have seen It needs to be declared,
One of basic difference(The command to check version)
in v2
etcdctl --version

in v3
etcdctl version

The issue in your command is not anywhere related to k8s - I don’t know what exactly it is termed(maybe other experts can let us know!) but it is how you input your commands to the underlying container (after --)
I guess as your command includes = and -- (in --help) which are leading your command to not get passed properly.

to pass your command properly try this

kubectl -n kube-system exec -it etcd-k8s-master -- sh -c "ETCDCTL_API=3 etcdctl --help"

this will pass your all commands and args properly

saip:
I always use just “–” and after that the command itself… Dont think we need “-it” here cause I dont need to attach to the terminal of the pod.

saip:
As you can see in the first command in my output above it worked ok.

Kratik Jain:
I am not saying anything about -it ,
Just use sh -c "WHOLE COMMAND" and you’ll be good to go

saip:
Yeah I get you.

saip:
Got rid of the previous messages that I put here for simplicity. I see what you mean about the usage of “=” in the command.

Kratik Jain:
The -c argument is: Read commands from the command_string operand instead of from the standard input.

saip:
Well the bit which really got me puzzled here is the whole backup works when I do this : kubectl -n kube-system exec etcd-k8s-master – etcdctl --cacert=“/etc/kubernetes/pki/etcd/ca.crt” --cert=“/etc/kubernetes/pki/etcd/server.crt” --key=“/etc/kubernetes/pki/etcd/server.key” --endpoints=127.0.0.1:2379 snapshot save /opt/test.db

saip:
That is why I said if etcd has changed with 3.4. I will rephrase my question for acrhiving purposes.

saip:
@Kratik Jain I tested it again and above command works like charm, at least in kubeadm based setup where etcd is a pod. So even without ETCDCTL_API=3 parameter it is always able to save the backup.

saip:
@Rahul Soni are you aware of any changes with etcd 3.4 ?

saip:
Well I found the answer, it has changed. API version is 3 by default with ETCD 3.4.0 : https://chromium.googlesource.com/external/github.com/coreos/etcd/+/refs/heads/master/CHANGELOG-3.4.md#breaking-changes

saip:
@Mumshad Mannambeth @Rahul Soni It would be great if this can be updated in the training for new people. ^^

Kratik Jain:
@saip can you try etcdctl version command as you tried above command,
If it’s ETCDCTL_API=3 , it will print the version otheriwise it will throw error.

saip:
I did that already, it is in my first message ^^^

saip:
Still pasting it here :

saip:
k8s-master:~$ kubectl -n kube-system exec etcd-k8s-master – etcdctl version
etcdctl version: 3.4.3
API version: 3.4