欢迎访问我的GitHub
这里分类和汇总了欣宸的全部原创(含配套源码):
https://github.com/zq2599/blog_demos
- kubernetes的API对象的数据都保存在etcd中,本章实战如何查看这些数据;
环境信息
- 实战环境的版本信息如下,请确保以下软件都已运行正常:
- 操作系统 :CentOS Linux release 7.6.1810
- Kubernetes:1.13
- Go版本:1.12
- 实际操作的机器可以用kubectl操作k8s,并且已经安装了Go 1.12版本;
准备工作
- 解压后找到etcdctl文件,将其放入$GOPATH\bin目录,记得执行chown命令给予可执行权限;
- 现在准备工作已经完成,接下来试试etcdctl工具查看etcd数据;
查看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
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
[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序列化后的数据,不过还是有部分内容是可读的;
- 查看节点信息,如下所示,当前环境有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及其含义
欢迎关注阿里云开发者社区博客:程序员欣宸
学习路上,你不孤单,欣宸原创一路相伴...