> For the complete documentation index, see [llms.txt](https://darren.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://darren.gitbook.io/project/k8s-xi-tong-wan-zheng-bu-shu/ru-he-shan-chu-etcd-shang-de-jiu-shu-ju.md).

# 如何删除etcd上的旧数据

1.查看etcd版本

```
> v2版本
etcdctl -v
> v3版本
etcdctl version
```

k8s默认使用的etcd V3版本API，ectdctl默认使用V2版本API，使用V2版本API查询不到k8s数据，需先切换到V3版本，设置环境变量即可

```
vim /etc/profile
##
export ETCDCTL_API=3

source /etc/profile
```

2.查询存储的所有key，并且前缀为'/'

```
etcdctl get / --prefix --keys-only
```

这条指令的意思是获取etcd中存储的所有key，并且前缀为 ‘/’，其结果类似于：

/registry/apiregistration.k8s.io/apiservices/v1.\
/registry/apiregistration.k8s.io/apiservices/v1.authentication.k8s.io\
对其中一个特定的键进行访问可以用一下方式进行：

etcdctl get /registry/apiregistration.k8s.io/apiservices/v1.

3.清除所有数据

```
etcdctl del / --prefix
```
