前言
Kubernetes中的etcd访问。

正常安装了k8s,没有特意去安装etcd,利用K8s中附带的etcd,感受一下etcd的读写操作。

提示:以下是本篇文章正文内容,下面案例可供参考

一、etcd是什么?
etcd是一个分布式的key-value存储数据库。

二、使用步骤
1.在k8s查看安装好的etcd
kubectl get pod -n kube-system | grep etcd
2.进入k8s的etcd
kubectl exec -ti etcd-s205 -n kube-system – /bin/sh
etcd-s205 是etcd的pod的名字,

kube-system是etcd所在的命名空间

3.指定etcd的版本3
export ETCDCTL_API=3

4.查看集群所有节点(etcdctl member list)
本来命令是etcdctl member list,会出错,

“level”:“warn”,“ts”:“2022-01-23T07:20:36.684Z”,“caller”:“clientv3/retry_interceptor.go:62”,“msg”:“retrying of unary invoker failed”,“target”:“endpoint://client-f4a0c47f-bfc5-4e20-938f-fd9f60be32fd/127.0.0.1:2379”,“attempt”:0,“error”:“rpc error: code = DeadlineExceeded desc = latest balancer error: all SubConns are in TransientFailure, latest connection error: connection closed”}
Error: context deadline exceeded

“level”:“warn”,“ts”:“2022-01-23T07:20:36.684Z”,“caller”:“clientv3/retry_interceptor.go:62”,“msg”:“retrying of unary invoker failed”,“target”:“endpoint://client-f4a0c47f-bfc5-4e20-938f-fd9f60be32fd/127.0.0.1:2379”,“attempt”:0,“error”:“rpc error: code = DeadlineExceeded desc = latest balancer error: all SubConns are in TransientFailure, latest connection error: connection closed”}
Error: context deadline exceeded
为了需要带上证书参数访问,

增加了证书参数

–cacert=/etc/kubernetes/pki/etcd/ca.crt

–cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt

–key=/etc/kubernetes/pki/etcd/healthcheck-client.key

etcdctl --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt --key=/etc/kubernetes/pki/etcd/healthcheck-client.key member list

5.写入测试数据(etcdctl put /testdir/testkey “Hello world1”)
etcdctl --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt --key=/etc/kubernetes/pki/etcd/healthcheck-client.key put /testdir/testkey “Hello world1”

6.读出测试数据(etcdctl get /testdir/testkey)
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 /testdir/testkey

总结
k8s中的etcd,加上证书参数后,就可以直接测试学习用了。
————————————————
版权声明:本文为CSDN博主「wuzd」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wuzd/article/details/122651639

Logo

开源、云原生的融合云平台

更多推荐