解决方案:Kubernetes 核心依赖组件 ETCD 的监控详解
优采云 发布时间: 2022-12-07 01:43解决方案:Kubernetes 核心依赖组件 ETCD 的监控详解
写在前面
蚀刻
是 Kubernetes 控制平面的重要组成部分和依赖关系,各种 Kubernetes 信息都存储在 ETCD 中,因此监控 ETCD 尤为重要。ETCD 在 Kubernetes 中的架构角色如下(仅与 APIServer 交互):
ETCD是一个类似Zookeeper的产品,通常由多个节点的集群组成,使用raft协议来确保节点之间的一致性。ETCD具有以下特点:
阅读 /metrics 界面
蚀刻
这样的云原生组件,明明内置了对 /metrics 接口的支持,但 ETCD 非常注重安全,默认访问 2379 端口是使用证书,我先测试一下:
[root@tt-fc-dev01.nj ~]# curl -k https://localhost:2379/metrics<br style="box-sizing: border-box;" />curl: (35) error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" />[root@tt-fc-dev01.nj ~]# ls /etc/kubernetes/pki/etcd<br style="box-sizing: border-box;" />ca.crt ca.key healthcheck-client.crt healthcheck-client.key peer.crt peer.key server.crt server.key<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" />[root@tt-fc-dev01.nj ~]# curl -s --cacert /etc/kubernetes/pki/etcd/ca.crt --cert /etc/kubernetes/pki/etcd/server.crt --key /etc/kubernetes/pki/etcd/server.key https://localhost:2379/metrics | head -n 6<br style="box-sizing: border-box;" /># HELP etcd_cluster_version Which version is running. 1 for 'cluster_version' label with current cluster version<br style="box-sizing: border-box;" /># TYPE etcd_cluster_version gauge<br style="box-sizing: border-box;" />etcd_cluster_version{cluster_version="3.5"} 1<br style="box-sizing: border-box;" /># HELP etcd_debugging_auth_revision The current revision of auth store.<br style="box-sizing: border-box;" /># TYPE etcd_debugging_auth_revision gauge<br style="box-sizing: border-box;" />etcd_debugging_auth_revision 1<br style="box-sizing: border-box;" />
对于使用 kubeadm 安装的 Kubernetes 集群,相关证书在 /etc/kubernetes/pki/etcd 目录中,并且为 curl 命令指定了相关证书,可以访问。之后,使用 Categraf 的普罗米修斯插件直接采集相关数据。
但是,真的没有必要对指标数据做这么强的安全控制,整体相当麻烦,事实上,ETCD 确实提供了另一个端口来获取指标数据,而无需经过这套证书认证机制。我们来看看 ETCD 启动命令,在 Kubernetes 系统中,直接导出 ETCD pod 的 yaml 信息:
kubectl get pod -n kube-system etcd-10.206.0.16 -o yaml<br style="box-sizing: border-box;" />
在上面的例子中,etcd-10.206.0.16 是我的 ETCD 的 pod 名称,你的可能是另一个名字,只需自己替换它即可。ETCD 的启动命令可以在输出中看到:
spec:<br style="box-sizing: border-box;" /> containers:<br style="box-sizing: border-box;" /> - command:<br style="box-sizing: border-box;" /> - etcd<br style="box-sizing: border-box;" /> - --advertise-client-urls=https://10.206.0.16:2379<br style="box-sizing: border-box;" /> - --cert-file=/etc/kubernetes/pki/etcd/server.crt<br style="box-sizing: border-box;" /> - --client-cert-auth=true<br style="box-sizing: border-box;" /> - --data-dir=/var/lib/etcd<br style="box-sizing: border-box;" /> - --initial-advertise-peer-urls=https://10.206.0.16:2380<br style="box-sizing: border-box;" /> - --initial-cluster=10.206.0.16=https://10.206.0.16:2380<br style="box-sizing: border-box;" /> - --key-file=/etc/kubernetes/pki/etcd/server.key<br style="box-sizing: border-box;" /> - --listen-client-urls=https://127.0.0.1:2379,https://10.206.0.16:2379<br style="box-sizing: border-box;" /> - --listen-metrics-urls=http://0.0.0.0:2381<br style="box-sizing: border-box;" /> - --listen-peer-urls=https://10.206.0.16:2380<br style="box-sizing: border-box;" /> - --name=10.206.0.16<br style="box-sizing: border-box;" /> - --peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt<br style="box-sizing: border-box;" /> - --peer-client-cert-auth=true<br style="box-sizing: border-box;" /> - --peer-key-file=/etc/kubernetes/pki/etcd/peer.key<br style="box-sizing: border-box;" /> - --peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt<br style="box-sizing: border-box;" /> - --snapshot-count=10000<br style="box-sizing: border-box;" /> - --trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt<br style="box-sizing: border-box;" /> image: registry.aliyuncs.com/google_containers/etcd:3.5.1-0<br style="box-sizing: border-box;" />注意 --
listen-metrics-urls=:2381 这一行,它实际上指定了端口 2381 直接获取指标数据,我们来测试一下:
[root@tt-fc-dev01.nj ~]# curl -s localhost:2381/metrics | head -n 6<br style="box-sizing: border-box;" /># HELP etcd_cluster_version Which version is running. 1 for 'cluster_version' label with current cluster version<br style="box-sizing: border-box;" /># TYPE etcd_cluster_version gauge<br style="box-sizing: border-box;" />etcd_cluster_version{cluster_version="3.5"} 1<br style="box-sizing: border-box;" /># HELP etcd_debugging_auth_revision The current revision of auth store.<br style="box-sizing: border-box;" /># TYPE etcd_debugging_auth_revision gauge<br style="box-sizing: border-box;" />etcd_debugging_auth_revision 1<br style="box-sizing: border-box;" />
非常好
好,那么我们就可以通过这个接口直接获取数据。
更多监控相关知识和SRE相关知识,欢迎加入我的学习
数据采集
ETCD的数据采集通常通过3种方式完成:
apiVersion: v1<br style="box-sizing: border-box;" />kind: Service<br style="box-sizing: border-box;" />metadata:<br style="box-sizing: border-box;" /> namespace: kube-system<br style="box-sizing: border-box;" /> name: etcd<br style="box-sizing: border-box;" /> labels:<br style="box-sizing: border-box;" /> k8s-app: etcd<br style="box-sizing: border-box;" />spec:<br style="box-sizing: border-box;" /> selector:<br style="box-sizing: border-box;" /> component: etcd<br style="box-sizing: border-box;" /> type: ClusterIP<br style="box-sizing: border-box;" /> clusterIP: None<br style="box-sizing: border-box;" /> ports:<br style="box-sizing: border-box;" /> - name: http<br style="box-sizing: border-box;" /> port: 2381<br style="box-sizing: border-box;" /> targetPort: 2381<br style="box-sizing: border-box;" /> protocol: TCP<br style="box-sizing: border-box;" />
如果您遵循 Prometheus Agent 模式采集方式,请注意抓取规则部分与前面提到的组件不同,并且您不需要使用 HTTPS:
- job_name: 'etcd'<br style="box-sizing: border-box;" /> kubernetes_sd_configs:<br style="box-sizing: border-box;" /> - role: endpoints<br style="box-sizing: border-box;" /> scheme: http<br style="box-sizing: border-box;" /> relabel_configs:<br style="box-sizing: border-box;" /> - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]<br style="box-sizing: border-box;" /> action: keep<br style="box-sizing: border-box;" /> regex: kube-system;etcd;http<br style="box-sizing: border-box;" />
挡泥板
此前,孔飞先生整理了ETCD的仪表盘,地址在,可以直接导入到夜莺中使用。
关键指标
ETCD也采集了很多指标,部分关键指标有以下含义,谢谢孔飞整理:
# HELP etcd_server_is_leader Whether or not this member is a leader. 1 if is, 0 otherwise.<br style="box-sizing: border-box;" /># TYPE etcd_server_is_leader gauge<br style="box-sizing: border-box;" />etcd leader 表示 ,1 leader 0 learner<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_health_success The total number of successful health checks<br style="box-sizing: border-box;" /># TYPE etcd_server_health_success counter<br style="box-sizing: border-box;" />etcd server 健康检查成功次数<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_health_failures The total number of failed health checks<br style="box-sizing: border-box;" /># TYPE etcd_server_health_failures counter<br style="box-sizing: border-box;" />etcd server 健康检查失败次数<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_disk_defrag_inflight Whether or not defrag is active on the member. 1 means active, 0 means not.<br style="box-sizing: border-box;" /># TYPE etcd_disk_defrag_inflight gauge<br style="box-sizing: border-box;" />是否启动数据压缩,1表示压缩,0表示没有启动压缩<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_snapshot_apply_in_progress_total 1 if the server is applying the incoming snapshot. 0 if none.<br style="box-sizing: border-box;" /># TYPE etcd_server_snapshot_apply_in_progress_total gauge<br style="box-sizing: border-box;" />是否再快照中,1 快照中,0 没有<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_leader_changes_seen_total The number of leader changes seen.<br style="box-sizing: border-box;" /># TYPE etcd_server_leader_changes_seen_total counter<br style="box-sizing: border-box;" />集群leader切换的次数<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP grpc_server_handled_total Total number of RPCs completed on the server, regardless of success or failure.<br style="box-sizing: border-box;" /># TYPE grpc_server_handled_total counter<br style="box-sizing: border-box;" />grpc 调用总数<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_disk_wal_fsync_duration_seconds The latency distributions of fsync called by WAL.<br style="box-sizing: border-box;" /># TYPE etcd_disk_wal_fsync_duration_seconds histogram<br style="box-sizing: border-box;" />etcd wal同步耗时<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_proposals_failed_total The total number of failed proposals seen.<br style="box-sizing: border-box;" /># TYPE etcd_server_proposals_failed_total counter<br style="box-sizing: border-box;" />etcd proposal(提议)失败总次数(proposal就是完成raft协议的一次请求)<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_proposals_pending The current number of pending proposals to commit.<br style="box-sizing: border-box;" /># TYPE etcd_server_proposals_pending gauge<br style="box-sizing: border-box;" />etcd proposal(提议)pending总次数(proposal就是完成raft协议的一次请求)<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_read_indexes_failed_total The total number of failed read indexes seen.<br style="box-sizing: border-box;" /># TYPE etcd_server_read_indexes_failed_total counter<br style="box-sizing: border-box;" />读取索引失败的次数统计(v3索引为所有key都建了索引,索引是为了加快range操作)<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_slow_read_indexes_total The total number of pending read indexes not in sync with leader's or timed out read index requests.<br style="box-sizing: border-box;" /># TYPE etcd_server_slow_read_indexes_total counter<br style="box-sizing: border-box;" />读取到过期索引或者读取超时的次数<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_server_quota_backend_bytes Current backend storage quota size in bytes.<br style="box-sizing: border-box;" /># TYPE etcd_server_quota_backend_bytes gauge<br style="box-sizing: border-box;" />当前后端的存储quota(db大小的上限)<br style="box-sizing: border-box;" />通过参数quota-backend-bytes调整大小,默认2G,官方建议不超过8G<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_mvcc_db_total_size_in_bytes Total size of the underlying database physically allocated in bytes.<br style="box-sizing: border-box;" /># TYPE etcd_mvcc_db_total_size_in_bytes gauge<br style="box-sizing: border-box;" />etcd 分配的db大小(使用量大小+空闲大小)<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_mvcc_db_total_size_in_use_in_bytes Total size of the underlying database logically in use in bytes.<br style="box-sizing: border-box;" /># TYPE etcd_mvcc_db_total_size_in_use_in_bytes gauge<br style="box-sizing: border-box;" />etcd db的使用量大小<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_mvcc_range_total Total number of ranges seen by this member.<br style="box-sizing: border-box;" /># TYPE etcd_mvcc_range_total counter<br style="box-sizing: border-box;" />etcd执行range的数量<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_mvcc_put_total Total number of puts seen by this member.<br style="box-sizing: border-box;" /># TYPE etcd_mvcc_put_total counter<br style="box-sizing: border-box;" />etcd执行put的数量<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_mvcc_txn_total Total number of txns seen by this member.<br style="box-sizing: border-box;" /># TYPE etcd_mvcc_txn_total counter<br style="box-sizing: border-box;" />etcd实例执行事务的数量<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP etcd_mvcc_delete_total Total number of deletes seen by this member.<br style="box-sizing: border-box;" /># TYPE etcd_mvcc_delete_total counter<br style="box-sizing: border-box;" />etcd实例执行delete操作的数量<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.<br style="box-sizing: border-box;" /># TYPE process_cpu_seconds_total counter<br style="box-sizing: border-box;" />etcd cpu使用量<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP process_resident_memory_bytes Resident memory size in bytes.<br style="box-sizing: border-box;" /># TYPE process_resident_memory_bytes gauge<br style="box-sizing: border-box;" />etcd 内存使用量<br style="box-sizing: border-box;" /><br style="box-sizing: border-box;" /># HELP process_open_fds Number of open file descriptors.<br style="box-sizing: border-box;" /># TYPE process_open_fds gauge<br style="box-sizing: border-box;" />etcd 打开的fd数目<br style="box-sizing: border-box;" />
相关文章 作者简介
本文的作者,Flashcat合作伙伴,文章
内容是Flashcat技术团队联合沉淀的结晶,作者经过编辑整理,我们将不断输出监控、稳定保障相关技术文章,文章可转载,请注明出处,尊重技术人员的成果。
如果您对南丁格尔、Categraf、普罗米修斯等技术感兴趣,欢迎加入我们的微信群,联系我(皮字节)拉入部落,与社区同事讨论监控技术。
核心方法:SEO优化师推荐:什么方法可以有效提升网站排名?
构建您自己的 网站,您如何才能使您的 网站 更易于搜索?此时,您需要针对 SEO 优化 网站。网站关键词 排名优化是SEO优化人员的日常工作。做SEO优化并不难。如果要优化网站的关键词在百度首页的排名,还取决于关键词竞争强度、优化时间、网站权重、seoer经验等因素,和优化技术。网站关键词 排名优化到百度首页。那么如何优化 网站 以提高排名呢?
1.确定网站的主要关键词并优化
总的来说,关键词 是网站 的灵魂。找到正确的关键词,就会找到正确的优化方向。关键词的质量直接影响网站的曝光率和转化率:关键词越多越好,而不是越少越好。如果是小的网站,建议关键词的个数不要太多,太多容易分散权重,不易优化,增加工作量和成本的优化。当然,我们不建议太少。太少的话,会降低网站的宣传力度,不利于网站的引流。
2、做好网站内部优化。
网站内部优化包括网站结构优化、网站地图制作、网页伪静态处理、死链接提交、404页面制作、网站内容优化等更多其中重要的是优化网站结构和网站内容。
搜索引擎优化
哪些方法可以有效提高网站排名?
首先说一下网站结构的优化。网站结构应该是扁平的或者树状的,这样更容易被搜索引擎抓取。同时尽量使用静态页面,因为搜索引擎喜欢静态页面。然后是内容优化。网站内容的优化可以有多种形式,比如文字、*敏*感*词*、图片等。
软文 带有文本锚文本可以很容易地将流量从一个页面引导到另一个页面,这是一种非常实用的内部优化方法。当然图片优化也是必须的,比如给图片添加关键词名字,添加ALT标签等。
3.站外优化。
首先,发布外链要注意链接内容的相关性。相关度越高,外链质量越好,流量越容易进来,转化率也会提高。相反,相关性低或内容不相关的外链是垃圾外链,不利于搜索引擎抓取和网站优化。下一步是交换友情链接。友情链接的交换也应该选择相关性高、质量好、权重高的网站进行交流。另外,应该对这些友情链接进行注册和跟踪,以便及时发现和处理意想不到的问题。
网站的文章内容应该和网站的主关键词相关,或者写在主关键词的长尾关键词周围。越有创意越好。让您的 文章 内容保持最新和大量,以便搜索引擎更有可能抓住您的 网站。同时,页面的标题要与页面的内容有一定的相关性。如果更新后的文章相关性不高,主题不突出,那么网站的关键词排名前期不会有太大优势,这也是综合大多数 网站 页面的排名 理由很充分。控制网页的相关性和关键字密度也可以提高关键字排名。