命令行太长了,不容易记住,使用alias命令用来设置指令的别名。
~~~
alias etcdctl="ETCDCTL_API=3 /usr/local/bin/etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt --key=/etc/kubernetes/pki/etcd/healthcheck-client.key"
~~~
1\. 查看所有etcd的所有key,执行以下命令:
~~~
root@k8s-master:~# etcdctl get / --prefix --keys-only。。。
/registry/services/specs/kube-system/kube-dns
/registry/services/specs/kube-system/tiller-deploy
/registry/services/specs/manually/sleep/registry/validatingwebhookconfigurations/istio-galley
root@k8s-master:~#
~~~
2\. 查看指定key的内容,如果您的系统用的是flannel网络插件,可以执行以下命令查看相关数据:
~~~
root@k8s-master:~# etcdctl get /registry/configmaps/kube-system/kube-flannel-cfg/registry/configmaps/kube-system/kube-flannel-cfgk8s v1 ConfigMap ¬ kube-flannel-cfg kube-system"*$2a0899cc-5dd7-42d6-9302-dbda856997532뫐ZappflannelZtiernodeb²0kubectl.kubernetes.io/last-applied-configurationiVersion":"v1","data":{"cni-conf.json":"{\n \"name\": \"cbr0\",\n \"cniVersion\": \"0.3.1\",\n \"plugins\": [\n {\n \"type\": \"flannel\",\n \"delegate\": {\n \"hairpinMode\": true,\n \"isDefaultGateway\": true\n }\n },\n {\n \"type\": \"portmap\",\n \"capabilities\": {\n \"portMappings\": true\n }\n }\n ]\n}\n","net-conf.json":"{\n \"Network\": \"10.244.0.0/16\",\n \"Backend\": {\n \"Type\": \"vxlan\"\n }\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app":"flannel","tier":"node"},"name":"kube-flannel-cfg","namespace":"kube-system"}}z¶ cni-conf.json¤{ "name": "cbr0", "cniVersion": "0.3.1", "plugins": [ { "type": "flannel", "delegate": { "hairpinMode": true, "isDefaultGateway": true } }, { "type": "portmap", "capabilities": { "portMappings": true } } ]}Znet-conf.jsonI{ "Network": "10.244.0.0/16", "Backend": { "Type": "vxlan" }}"XshellXshellroot@k8s-master:~#
~~~
如上所示,有少量不可见字符,这是因为etcd中存储的并不是json的原文,而是protocol buffer序列化后的数据,不过还是有部分内容是可读的;
3\. 查看节点信息,如下所示,当前环境有master和node0两个节点:
~~~
root@k8s-master:~# etcdctl get /registry/minions/ --prefix --keys-only/registry/minions/k8s-master/registry/minions/k8s-node root@k8s-master:~#
~~~
1. 执行以下命令可以查看node0节点的信息,由于结果中有很多序列化之后的不可读字符,就不把结果贴出来了:
~~~
etcdctl get /registry/minions/k8s-node
~~~
## etcd中的key及其含义