查看k8s集群数据
ETCDCTL_API=3 /usr/local/bin/etcdctl --cacert=/etc/etcd/ssl/ca.pem --cert=/etc/etcd/ssl/etcd.pem --key=/etc/etcd/ssl/etcd-key.pem --endpoints="https://xxxx,https://xxxx:2379,https://xxxx:2379" get / --prefix --keys-only
查看etcd数据的实际操作
执行查询时前缀是固定的,如下所示,使用这个前缀再加上etcd的查找命令即可成功查询:
ETCDCTL_API=3 ./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
2
3
4
查看所有etcd的所有key,执行以下命令:
ETCDCTL_API=3 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 \
get / --prefix --keys-only
1
2
3
4
5
6
查到的结果如下:
[root@master ~]# ETCDCTL_API=3 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 \
> get / --prefix --keys-only
/registry/apiregistration.k8s.io/apiservices/v1.
/registry/apiregistration.k8s.io/apiservices/v1.apps
/registry/apiregistration.k8s.io/apiservices/v1.authentication.k8s.io
/registry/apiregistration.k8s.io/apiservices/v1.authorization.k8s.io
/registry/apiregistration.k8s.io/apiservices/v1.autoscaling
/registry/apiregistration.k8s.io/apiservices/v1.batch
/registry/apiregistration.k8s.io/apiservices/v1.networking.k8s.io
...
查看指定key的内容,如果您的系统用的是flannel网络插件,可以执行以下命令查看相关数据:
ETCDCTL_API=3 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 \
get /registry/configmaps/kube-system/kube-flannel-cfg
看到的数据如下所示:
[root@master ~]# ETCDCTL_API=3 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 \
> get /registry/configmaps/kube-system/kube-flannel-cfg
/registry/configmaps/kube-system/kube-flannel-cfg
k8s
v1 ConfigMap?
?
kube-flannel-cfg
kube-system"*$c2b898e2-3a58-11e9-86b5-000c292593442????Z
appflannelZ
tiernodeb?
0kubectl.kubernetes.io/last-applied-configuration?{"apiVersion":"v1","data":{"cni-conf.json":"{\n \"name\": \"cbr0\",\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",
"plugins": [
{
"type": "flannel",
"delegate": {
"hairpinMode": true,
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
Z
net-conf.jsonI{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "vxlan"
}
}
"
如上所示,有少量不可见字符,这是因为etcd中存储的并不是json的原文,而是protocol buffer序列化后的数据,不过还是有部分内容是可读的;
3. 查看节点信息,如下所示,当前环境有master和node0两个节点:
[root@master ~]# ETCDCTL_API=3 etcdctl \
> --cacert=/etc/kubernetes/pki/etcd/ca.crt \
> --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt \
> --key=/etc/kubernetes/pki/etcd/healthcheck-client.key \
> get /registry/minions/ --prefix --keys-only
/registry/minions/master
/registry/minions/node0
执行以下命令可以查看node0节点的信息,由于结果中有很多序列化之后的不可读字符,就不把结果贴出来了:
ETCDCTL_API=3 etcdctl \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt \
--key=/etc/kubernetes/pki/etcd/healthcheck-client.key \
get /registry/minions/node0
etcd中的key及其含义
关于kubernetes的etcd中有哪些key以及它们的含义,可以这篇文章中有更详细的说明:https://jakubbujny.com/2018/09/02/what-stores-kubernetes-in-etcd/
至此,kubernetes环境下如何查看etcd存储的数据的实战就完成了,希望能够帮助您快速查看k8s系统的数据。
————————————————
版权声明:本文为CSDN博主「程序员欣宸」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/boling_cavalry/article/details/88958242