{"id":12174,"date":"2023-03-15T18:36:03","date_gmt":"2023-03-15T10:36:03","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=12174"},"modified":"2023-03-16T16:45:42","modified_gmt":"2023-03-16T08:45:42","slug":"etcd-2","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2023\/03\/15\/etcd-2\/","title":{"rendered":"\u901a\u8fc7\u591c\u83ba\u76d1\u63a7etcd"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">ETCD \u662f Kubernetes \u63a7\u5236\u9762\u7684\u91cd\u8981\u7ec4\u4ef6\u548c\u4f9d\u8d56\uff0ck8s\u4e2d\u5404\u4e2a\u7ec4\u4ef6\u7684\u4fe1\u606f\u90fd\u5b58\u50a8\u5728etcd\u4e2d\uff0c\u56e0\u6b64\u76d1\u63a7etcd\u4e5f\u5f88\u91cd\u8981<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ETCD \u7684\u6570\u636e\u91c7\u96c6\u901a\u5e38\u4f7f\u7528 3 \u79cd\u65b9\u5f0f<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f7f\u7528 ETCD \u6240\u5728\u5bbf\u4e3b\u7684 agent \u76f4\u63a5\u6765\u91c7\u96c6\uff0c\u56e0\u4e3a ETCD \u662f\u4e2a\u9759\u6001 Pod\uff0c\u6240\u4ee5 agent \u76f4\u63a5\u8fde\u4e0a\u53bb\u91c7\u96c6\u5373\u53ef<\/li><li>\u628a\u91c7\u96c6\u5668\u548c ETCD \u505a\u6210 sidecar \u7684\u6a21\u5f0f<\/li><li>\u4f7f\u7528\u670d\u52a1\u53d1\u73b0\u673a\u5236\uff0c\u5728\u4e2d\u5fc3\u7aef\u90e8\u7f72\u91c7\u96c6\u5668\uff0c\u4e0e\u91c7\u96c6apiserver\u3001controller-manager\u4e00\u6837<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">etcd\u5185\u7f6e\u4e86\/metrics\u63a5\u53e3\uff0c\u901a\u8fc72379\u7aef\u53e3\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u6307\u6807\u6570\u636e\uff0c\u4f46\u662f\u8bbf\u95ee\u662f\u9700\u8981\u8bc1\u4e66\u7684\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"91\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/8-6.png\" alt=\"\" class=\"wp-image-12178\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/8-6.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/8-6-300x38.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/8-6-600x77.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7kubeadm\u5b89\u88c5\u7684\u96c6\u7fa4\uff0c\u8bc1\u4e66\u4f4d\u7f6e\u4e00\u822c\u5728\/etc\/kubernetes\/pki\/etcd\u8def\u5f84\u4e0b\uff0c\u901a\u8fc7\u8bc1\u4e66\u4ee5\u53cacategraf\u7684prometheus\u63d2\u4ef6\u5373\u53ef\u83b7\u53d6\u6570\u636e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e862379\u7aef\u53e3\u5916\uff0cetcd\u8fd8\u63d0\u4f9b\u4e862381\u8fd9\u4e2a\u7aef\u53e3\u7528\u6765\u83b7\u53d6\u6307\u6807\u6570\u636e\uff0c\u6b64\u7aef\u53e3\u4e0d\u9700\u8981\u8bc1\u4e66\uff0c\u67e5\u770betcd.yaml\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/kubernetes\/manifests\/etcd.yaml<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"196\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/9-6.png\" alt=\"\" class=\"wp-image-12179\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/9-6.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/9-6-300x83.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/9-6-600x166.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u6b64\u5730\u5740\u6d4b\u8bd5\u53d1\u73b0\u5df2\u7ecf\u53ef\u4ee5\u91c7\u96c6\u5230\u6570\u636e\uff0c\u6ce8\u610f\u662fhttp\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"291\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/10-5.png\" alt=\"\" class=\"wp-image-12180\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/10-5.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/10-5-300x123.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/10-5-600x246.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u672c\u4f8b\u5b50\u4e2d\u4f9d\u7136\u901a\u8fc7\u670d\u52a1\u53d1\u73b0\u673a\u5236\u6765\u91c7\u96c6\u6570\u636e\uff0c\u7ee7\u7eed\u4fee\u6539\u91c7\u96c6apiserver\u548ccontroller\u65f6\u7528\u7684prometheus.yml\u6587\u4ef6\uff0c\u6dfb\u52a0etcd\u76f8\u5173\u5185\u5bb9\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- job_name: 'etcd'\n        kubernetes_sd_configs:\n        - role: endpoints\n        scheme: http\n        relabel_configs:\n        - source_labels: &#91;__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]\n          action: keep\n          regex: kube-system;etcd;http\n<\/code><\/pre>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u4e0a\u56fe\u4e2d\u7684source_labels\u7684\u4e09\u4e2a\u503c\uff0c\u5bf9\u5e94\u7684\u5c31\u662f\u4e0b\u9762regex\u7684\u4e09\u4e2a\u503c\uff0c\u547d\u540d\u7a7a\u95f4\u4e3akube-system\uff0c\u670d\u52a1\u540d\u4e3aetcd\uff0cep\u7684\u7aef\u53e3\u540d\u4e3ahttp<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u7684\u670d\u52a1\u540detcd\u548cendpoint\u7684\u7aef\u53e3\u540d\u5e76\u4e0d\u5b58\u5728\uff0c\u56e0\u6b64\u9700\u8981\u65b0\u5efa\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: Service\nmetadata:\n  namespace: kube-system\n  name: etcd\n  labels:\n    k8s-app: etcd\nspec:\n  selector:\n    component: etcd                    #\u6807\u7b7e\u662f\u5b89\u88c5etcd\u65f6\u5c31\u5df2\u7ecf\u81ea\u5e26\u7684\u4e86\n  type: ClusterIP\n  clusterIP: None\n  ports:\n    - name: http\n      port: 2381\n      targetPort: 2381\n      protocol: TCP<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"136\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/12-4.png\" alt=\"\" class=\"wp-image-12187\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/12-4.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/12-4-300x58.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/12-4-600x115.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u4fee\u6539etcd\u914d\u7f6e\u6587\u4ef6\u5730\u5740\uff0c\u6539\u4e3a0.0.0.0\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/kubernetes\/manifests\/etcd.yaml<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"244\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/13-3.png\" alt=\"\" class=\"wp-image-12190\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/13-3.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/13-3-300x103.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/13-3-600x206.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u91cd\u542fprometheus agent mode\u7684pod\uff0c\u5e76\u4e14\u5e94\u7528\u8d44\u6e90\u6587\u4ef6\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl rollout restart deploy prometheus-agent -n monitor\nkubectl apply -f prometheus.yml\r<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728\u591c\u83ba\u63a7\u5236\u9762\u677f\u5373\u65f6\u67e5\u8be2\u91cc\u67e5\u770b\u76d1\u63a7\u6307\u6807\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"388\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/14-4.png\" alt=\"\" class=\"wp-image-12192\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/14-4.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/14-4-300x165.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/14-4-600x329.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\uff1a\u5982\u679c\u6ca1\u6709\u6307\u6807\uff0c\u53ef\u68c0\u67e5prometheus agent \u5bb9\u5668\u5185\u90e8\/etc\/prometheus\/prometheus.yml\u4e2d\u7684etcd\u914d\u7f6e\u662f\u5426\u52a0\u8f7d\u8fdb\u6765(\u901a\u8fc7configMap\u6302\u8f7d\u8fdb\u53bb\u7684)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9644\u52a0\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6709\u591a\u4e2a\u76f8\u540c\u7684\u76d1\u63a7\u6307\u6807\uff0c\u53ef\u6839\u636ejob\u540d\u5b57\u533a\u5206\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"312\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/15-4.png\" alt=\"\" class=\"wp-image-12199\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/15-4.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/15-4-300x132.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/03\/15-4-600x265.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u952e\u6307\u6807\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># HELP etcd_server_is_leader Whether or not this member is a leader. 1 if is, 0 otherwise.\n# TYPE etcd_server_is_leader gauge\netcd leader \u8868\u793a \uff0c1 leader 0 learner\n\n# HELP etcd_server_health_success The total number of successful health checks\n# TYPE etcd_server_health_success counter\netcd server \u5065\u5eb7\u68c0\u67e5\u6210\u529f\u6b21\u6570\n\n# HELP etcd_server_health_failures The total number of failed health checks\n# TYPE etcd_server_health_failures counter\netcd server \u5065\u5eb7\u68c0\u67e5\u5931\u8d25\u6b21\u6570\n\n# HELP etcd_disk_defrag_inflight Whether or not defrag is active on the member. 1 means active, 0 means not.\n# TYPE etcd_disk_defrag_inflight gauge\n\u662f\u5426\u542f\u52a8\u6570\u636e\u538b\u7f29\uff0c1\u8868\u793a\u538b\u7f29\uff0c0\u8868\u793a\u6ca1\u6709\u542f\u52a8\u538b\u7f29\n\n# HELP etcd_server_snapshot_apply_in_progress_total 1 if the server is applying the incoming snapshot. 0 if none.\n# TYPE etcd_server_snapshot_apply_in_progress_total gauge\n\u662f\u5426\u518d\u5feb\u7167\u4e2d\uff0c1 \u5feb\u7167\u4e2d\uff0c0 \u6ca1\u6709\n\n# HELP etcd_server_leader_changes_seen_total The number of leader changes seen.\n# TYPE etcd_server_leader_changes_seen_total counter\n\u96c6\u7fa4leader\u5207\u6362\u7684\u6b21\u6570\n\n# HELP grpc_server_handled_total Total number of RPCs completed on the server, regardless of success or failure.\n# TYPE grpc_server_handled_total counter\ngrpc \u8c03\u7528\u603b\u6570\n\n# HELP etcd_disk_wal_fsync_duration_seconds The latency distributions of fsync called by WAL.\n# TYPE etcd_disk_wal_fsync_duration_seconds histogram\netcd wal\u540c\u6b65\u8017\u65f6\n\n# HELP etcd_server_proposals_failed_total The total number of failed proposals seen.\n# TYPE etcd_server_proposals_failed_total counter\netcd proposal\uff08\u63d0\u8bae\uff09\u5931\u8d25\u603b\u6b21\u6570(proposal\u5c31\u662f\u5b8c\u6210raft\u534f\u8bae\u7684\u4e00\u6b21\u8bf7\u6c42\uff09\n\n# HELP etcd_server_proposals_pending The current number of pending proposals to commit.\n# TYPE etcd_server_proposals_pending gauge\netcd proposal\uff08\u63d0\u8bae\uff09pending\u603b\u6b21\u6570\uff08proposal\u5c31\u662f\u5b8c\u6210raft\u534f\u8bae\u7684\u4e00\u6b21\u8bf7\u6c42\uff09\n\n# HELP etcd_server_read_indexes_failed_total The total number of failed read indexes seen.\n# TYPE etcd_server_read_indexes_failed_total counter\n\u8bfb\u53d6\u7d22\u5f15\u5931\u8d25\u7684\u6b21\u6570\u7edf\u8ba1(v3\u7d22\u5f15\u4e3a\u6240\u6709key\u90fd\u5efa\u4e86\u7d22\u5f15\uff0c\u7d22\u5f15\u662f\u4e3a\u4e86\u52a0\u5febrange\u64cd\u4f5c)\n\n# 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.\n# TYPE etcd_server_slow_read_indexes_total counter\n\u8bfb\u53d6\u5230\u8fc7\u671f\u7d22\u5f15\u6216\u8005\u8bfb\u53d6\u8d85\u65f6\u7684\u6b21\u6570\n\n# HELP etcd_server_quota_backend_bytes Current backend storage quota size in bytes.\n# TYPE etcd_server_quota_backend_bytes gauge\n\u5f53\u524d\u540e\u7aef\u7684\u5b58\u50a8quota\uff08db\u5927\u5c0f\u7684\u4e0a\u9650\uff09\n\u901a\u8fc7\u53c2\u6570quota-backend-bytes\u8c03\u6574\u5927\u5c0f\uff0c\u9ed8\u8ba42G\uff0c\u5b98\u65b9\u5efa\u8bae\u4e0d\u8d85\u8fc78G\n\n# HELP etcd_mvcc_db_total_size_in_bytes Total size of the underlying database physically allocated in bytes.\n# TYPE etcd_mvcc_db_total_size_in_bytes gauge\netcd \u5206\u914d\u7684db\u5927\u5c0f\uff08\u4f7f\u7528\u91cf\u5927\u5c0f+\u7a7a\u95f2\u5927\u5c0f\uff09\n\n# HELP etcd_mvcc_db_total_size_in_use_in_bytes Total size of the underlying database logically in use in bytes.\n# TYPE etcd_mvcc_db_total_size_in_use_in_bytes gauge\netcd db\u7684\u4f7f\u7528\u91cf\u5927\u5c0f\n\n# HELP etcd_mvcc_range_total Total number of ranges seen by this member.\n# TYPE etcd_mvcc_range_total counter\netcd\u6267\u884crange\u7684\u6570\u91cf\n\n# HELP etcd_mvcc_put_total Total number of puts seen by this member.\n# TYPE etcd_mvcc_put_total counter\netcd\u6267\u884cput\u7684\u6570\u91cf\n\n# HELP etcd_mvcc_txn_total Total number of txns seen by this member.\n# TYPE etcd_mvcc_txn_total counter\netcd\u5b9e\u4f8b\u6267\u884c\u4e8b\u52a1\u7684\u6570\u91cf\n\n# HELP etcd_mvcc_delete_total Total number of deletes seen by this member.\n# TYPE etcd_mvcc_delete_total counter\netcd\u5b9e\u4f8b\u6267\u884cdelete\u64cd\u4f5c\u7684\u6570\u91cf\n\n# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.\n# TYPE process_cpu_seconds_total counter\netcd cpu\u4f7f\u7528\u91cf\n\n# HELP process_resident_memory_bytes Resident memory size in bytes.\n# TYPE process_resident_memory_bytes gauge\netcd \u5185\u5b58\u4f7f\u7528\u91cf\n\n# HELP process_open_fds Number of open file descriptors.\n# TYPE process_open_fds gauge\netcd \u6253\u5f00\u7684fd\u6570\u76ee<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ETCD \u662f Kubernetes \u63a7\u5236\u9762\u7684\u91cd\u8981\u7ec4\u4ef6\u548c\u4f9d\u8d56\uff0ck8s\u4e2d\u5404\u4e2a\u7ec4\u4ef6\u7684\u4fe1\u606f\u90fd\u5b58\u50a8\u5728etcd\u4e2d\uff0c\u56e0\u6b64\u76d1\u63a7 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":12176,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93,109],"tags":[],"class_list":["post-12174","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kubernetes","category-didi"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/12174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=12174"}],"version-history":[{"count":15,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/12174\/revisions"}],"predecessor-version":[{"id":12222,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/12174\/revisions\/12222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/12176"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=12174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=12174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=12174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}