{"id":142175,"date":"2019-04-22T08:32:23","date_gmt":"2019-04-22T00:32:23","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=142175"},"modified":"2019-04-10T12:34:22","modified_gmt":"2019-04-10T04:34:22","slug":"kubernetes-monitor-heapster","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/kubernetes-monitor-heapster.html","title":{"rendered":"\u4ecb\u7ecdKubernetes\u76d1\u63a7Heapster"},"content":{"rendered":"
\u4ec0\u4e48\u662fHeapster\uff1f<\/strong><\/span><\/div>\n

Heapster\u662f\u5bb9\u5668\u96c6\u7fa4\u76d1\u63a7\u548c\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u5929\u7136\u7684\u652f\u6301Kubernetes\u548cCoreOS,Kubernetes\u6709\u4e2a\u51fa\u540d\u7684\u76d1\u63a7agent\u2014cAdvisor\u3002\u5728\u6bcf\u4e2akubernetes Node\u4e0a\u90fd\u4f1a\u8fd0\u884ccAdvisor\uff0c\u5b83\u4f1a\u6536\u96c6\u672c\u673a\u4ee5\u53ca\u5bb9\u5668\u7684\u76d1\u63a7\u6570\u636e(cpu,memory,filesystem,network,uptime),\u5728\u8f83\u65b0\u7684\u7248\u672c\u4e2d\uff0cK8S\u5df2\u7ecf\u5c06cAdvisor\u529f\u80fd\u96c6\u6210\u5230kubelet\u7ec4\u4ef6\u4e2d\u3002\u6bcf\u4e2aNode\u8282\u70b9\u53ef\u4ee5\u76f4\u63a5\u8fdb\u884cweb\u8bbf\u95ee\u3002<\/p>\n

\r\ncAdvisor web\u754c\u9762\u8bbf\u95ee\uff1a http:\/\/< Node-IP >:4194\r\n\r\ncAdvisor\u4e5f\u63d0\u4f9bRestful API: https:\/\/github.com\/google\/cadv \u2026 pi.md\r\n<\/pre>\n

Heapster\u662f\u4e00\u4e2a\u6536\u96c6\u8005\uff0c\u5c06\u6bcf\u4e2aNode\u4e0a\u7684cAdvisor\u7684\u6570\u636e\u8fdb\u884c\u6c47\u603b\uff0c\u7136\u540e\u5bfc\u5230\u7b2c\u4e09\u65b9\u5de5\u5177(\u5982InfluxDB)\u3002<\/p>\n

\u6846\u67b6\u56fe<\/strong><\/span><\/div>\n

\"\"<\/p>\n

Heapster\u9996\u5148\u4eceK8S Master\u83b7\u53d6\u96c6\u7fa4\u4e2d\u6240\u6709Node\u7684\u4fe1\u606f\uff0c\u7136\u540e\u901a\u8fc7\u8fd9\u4e9bNode\u4e0a\u7684kubelet\u83b7\u53d6\u6709\u7528\u6570\u636e\uff0c\u800ckubelet\u672c\u8eab\u7684\u6570\u636e\u5219\u662f\u4ececAdvisor\u5f97\u5230\u3002\u6240\u6709\u83b7\u53d6\u5230\u7684\u6570\u636e\u90fd\u88ab\u63a8\u5230Heapster\u914d\u7f6e\u7684\u540e\u7aef\u5b58\u50a8\u4e2d\uff0c\u5e76\u8fd8\u652f\u6301\u6570\u636e\u7684\u53ef\u89c6\u5316\u3002\u73b0\u5728\u540e\u7aef\u5b58\u50a8 + \u53ef\u89c6\u5316\u7684\u65b9\u6cd5\uff0c\u5982InfluxDB + grafana\u3002<\/p>\n

Heapster\u4f7f\u7528<\/strong><\/span><\/div>\n

\u8fd9\u91cc\u4e3b\u8981\u4ecb\u7ecdHeapster\u7684API\u4f7f\u7528\uff0c\u53ca\u53ef\u83b7\u53d6\u7684Metrics;API\u6587\u6863\u53ca\u53ef\u7528Metrics\u5728\u5b98\u65b9\u6587\u6863\u4e2d\u90fd\u4ecb\u7ecd\u7684\u6bd4\u8f83\u9f50\u5168\u3002\u4e0b\u9762\u7528\u51e0\u6761\u6d4b\u8bd5\u547d\u4ee4\u6765\u89e3\u91caAPI\u4f7f\u7528,\u83b7\u53d6\u652f\u6301\u7684metrics<\/p>\n

\r\ncurl -L http:\/\/:8082\/api\/v1\/model\/metrics\r\n<\/heapster><\/pre>\n

\u5217\u51fa\u6240\u6709\u7684Nodes\u652f\u6301\u7684metrics<\/p>\n

\r\ncurl -L http:\/\/:8082\/api\/v1\/model\/nodes\/metrics\r\n<\/heapster><\/pre>\n

\u67e5\u770b\u5bf9\u5e94Pod\u7684cpu\u4f7f\u7528\u7387<\/p>\n

\r\ncurl -L http:\/\/:8082\/api\/v1\/model\/namespaces\/\/pods\/\/metrics\/cpu-usage\r\n<\/pod><\/namespace><\/heapster><\/pre>\n
Heapster\u7cfb\u7edf\u90e8\u7f72<\/strong><\/span><\/div>\n

\u6211\u4eec\u91c7\u7528Heapster\u4ee5InfluxDB\u4f5c\u4e3a\u6570\u636e\u5b58\u50a8\u540e\u7aef\uff0c\u518d\u914d\u5408Grafana\u7684\u524d\u7aef\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u7684\u7cfb\u7edf\u76d1\u63a7\u65b9\u6848\uff0c\u8fdb\u884c\u90e8\u7f72\u3002<\/p>\n

\r\n\u955c\u50cf\u5236\u4f5c\uff1a\r\nHeapster\u7684\u7248\u672c\uff1av0.19.0\r\n\r\n\u6ca1\u6709\u91c7\u7528\u6700\u65b0\u7684Heapster\u7248\u672c\uff0c\u662f\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u7684Kubernets\u7248\u672c\u4e3a\u8f83\u65e7\u7684v1.0.3\uff0c\u8f83\u65b0\u7684Heapster\u7248\u672c\u4e0d\u517c\u5bb9\u8be5K8S\u7248\u672c\u3002\r\n\r\nHeapster\u955c\u50cf\uff1a\r\n\u8fdb\u5165heapster-0.19.0\/\/deploy\/docker,\u4f7f\u7528build.sh\u8fdb\u884c\u955c\u50cf\u5236\u4f5c\u3002 \u8be5\u811a\u672c\u4f1a\u4f9d\u8d56go\u73af\u5883\u8fdb\u884cheapster\u6e90\u7801\u7f16\u8bd1\uff0c\u6240\u4ee5\u9700\u8981\u63d0\u524d\u5b89\u88c5go\u73af\u5883(go\u548cgodep\u7684\u5b89\u88c5)\u3002\r\n\r\nInfluxDB\u548cGrafana\u955c\u50cf\uff1a\r\n\u8fd9\u4e24\u4e2a\u955c\u50cf\u7684Dockerfile\u5206\u522b\u5728\u6839\u76ee\u5f55\u4e0b\u7684\u5bf9\u5e94\u6587\u4ef6\u4e2d\uff0c\u53ea\u9700\u67e5\u770bMakefile\u8fdb\u884c\u5bf9\u5e94\u7684\u547d\u4ee4\u7f16\u8bd1\u5236\u4f5c\u955c\u50cf\u5373\u53ef\u3002Dockerfile\u4f1a\u4f9d\u8d56\u4e00\u4e9b\u57fa\u7840\u955c\u50cf\uff0c\u6700\u597d\u63d0\u524d\u4e0b\u8f7d\u597d\u3002\r\n<\/pre>\n
\u5bb9\u5668\u7684\u8fd0\u884c<\/strong><\/span><\/div>\n

Heapster\u5bb9\u5668\u7684\u8fd0\u884c\u53ef\u4ee5\u4f9d\u8d56Kubernetes\u8fdb\u884c\u90e8\u7f72\uff0c\u4e5f\u53ef\u4ee5\u5355\u72ec\u4f7f\u7528docker\u547d\u4ee4\u8fdb\u884c\u90e8\u7f72\u3002<\/p>\n

Kubernetes\u90e8\u7f72<\/strong><\/span><\/div>\n

\u76f4\u63a5\u4f9d\u8d56heapster-0.19.0\/deploy\/kube-config\/influxdb\/\u76ee\u5f55\u4e0b\u7684yaml\u6587\u4ef6\uff0c\u4f7f\u7528kubectl create -f heapster-0.19.0\/deploy\/kube-config\/influxdb\/\u547d\u4ee4\u8fdb\u884c\u90e8\u7f72\u3002<\/p>\n

\u6211\u4eec\u6ca1\u6709\u91c7\u7528\u8be5\u65b9\u5f0f\uff0c\u662f\u8003\u8651\u5230\u5982\u679cK8S\u548c\u76d1\u63a7\u7cfb\u7edf\u76f8\u4e92\u4f9d\u8d56\uff0c\u4f1a\u5bfc\u81f4K8S\u5f02\u5e38\u4e4b\u540e\uff0c\u5b58\u5728\u76d1\u63a7\u7cfb\u7edf\u65e0\u6cd5\u4f7f\u7528\u7684\u9690\u60a3\u3002<\/p>\n

\u4f46\u662f\u76f4\u63a5\u4f7f\u7528\u5355\u72ec\u7684\u5bb9\u5668\u8fdb\u884c\u90e8\u7f72\uff0c\u4e5f\u9700\u8981\u8003\u8651\u5230\u76d1\u63a7\u5bb9\u5668\u5f02\u5e38\u9000\u51fa\u4e86\uff0c\u8c01\u6765\u7ef4\u62a4\u91cd\u542f\uff1f<\/p>\n

\u9700\u8981\u8fdb\u884c\u6743\u8861\uff1f<\/p>\n

\u8fd8\u9700\u8981\u6ce8\u610f\u4e00\u70b9\uff1aHeapster\u4f1a\u4f7f\u7528\u5185\u5b58\u8fdb\u884c\u6570\u636e\u7f13\u5b58\uff0c\u5bb9\u6613\u6491\u7206\u5185\u5b58\uff0c\u5bfc\u81f4\u5bb9\u5668OOM<\/p>\n

Docker\u547d\u4ee4\u90e8\u7f72<\/strong><\/span><\/div>\n

\u4f7f\u7528docker\u547d\u4ee4\u8fdb\u884c\u90e8\u7f72\u7684\u8bdd\uff0c\u9700\u8981\u4f20\u5165\u5404\u79cd\u53c2\u6570\uff0c\u8be5\u53c2\u6570\u53ef\u4ee5\u53c2\u8003kubernetes\u90e8\u7f72\u4f7f\u7528\u5230\u7684yaml\u6587\u4ef6\u3002<\/p>\n

\u5177\u4f53\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

InfluxDB<\/strong><\/span><\/div>\n

docker run -p 8083:8083 -p 8086:8086 --net=host -v \/data heapster_influxdb:canary
\n\u6ce8\uff1adata\u662f\u6570\u636e\u5b58\u50a8\u76ee\u5f55\uff0c\u9700\u8981\u8003\u8651\u6570\u636e\u53ef\u6301\u4e45\u5316\uff0c\u5e76\u4e14\u80fd\u4fdd\u8bc1\u5bb9\u5668\u91cd\u542f\u4e0d\u5f71\u54cd\u6570\u636e\u3002<\/p>\n

Grafana<\/strong><\/span><\/div>\n
\r\ndocker run -p 3000:3000 --net=host -e INFLUXDB_SERVICE_URL=http:\/\/:8086 -e GF_AUTH_BASIC_ENABLED=\"false\" -e GF_AUTH_ANONYMOUS_ENABLED=\"true\" -e GF_AUTH_ANONYMOUS_ORG_ROLE=\"Admin\" -e GF_SERVER_ROOT_URL=\/ -v \/var heapster_grafana:canary\r\n<\/influxdb><\/pre>\n
Heapster<\/strong><\/span><\/div>\n
\r\ndocker run -it -p 8082:8082 --net=host heapster:canary --source=kubernetes:http:\/\/:8080?inClusterConfig=false\\&useServiceAccount=false --sink=influxdb:http:\/\/:8086\r\n<\/influxdb><\/k8s><\/pre>\n

Heapster\u547d\u4ee4\u53c2\u8003\u76f8\u5bf9\u8f83\u4e3a\u91cd\u8981\uff0c\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n

\r\n\u2013source: \u6307\u5b9a\u6570\u636e\u83b7\u53d6\u6e90\u3002\u8fd9\u91cc\u6211\u4eec\u6307\u5b9akube-apiserver\u5373\u53ef\u3002\r\n\u540e\u7f00\u53c2\u6570\uff1a\r\ninClusterConfig:\r\nkubeletPort: \u6307\u5b9akubelet\u7684\u4f7f\u7528\u7aef\u53e3\uff0c\u9ed8\u8ba410255\r\nkubeletHttps: \u662f\u5426\u4f7f\u7528https\u53bb\u8fde\u63a5kubelets(\u9ed8\u8ba4\uff1afalse)\r\napiVersion: \u6307\u5b9aK8S\u7684apiversion\r\ninsecure: \u662f\u5426\u4f7f\u7528\u5b89\u5168\u8bc1\u4e66(\u9ed8\u8ba4\uff1afalse)\r\nauth: \u5b89\u5168\u8ba4\u8bc1\r\nuseServiceAccount: \u662f\u5426\u4f7f\u7528K8S\u7684\u5b89\u5168\u4ee4\u724c\r\n\r\n\u2013sink: \u6307\u5b9a\u540e\u7aef\u6570\u636e\u5b58\u50a8\u3002\u8fd9\u91cc\u6307\u5b9ainfluxdb\u6570\u636e\u5e93\u3002\r\n\u540e\u7f00\u53c2\u6570\uff1a\r\nuser: InfluxDB\u7528\u6237\r\npw: InfluxDB\u5bc6\u7801\r\ndb: \u6570\u636e\u5e93\u540d\r\nsecure: \u5b89\u5168\u8fde\u63a5\u5230InfluxDB(\u9ed8\u8ba4\uff1afalse)\r\nwithfields\uff1a \u4f7f\u7528InfluxDB fields(\u9ed8\u8ba4\uff1afalse)\u3002\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Heapster\u662f\u5bb9\u5668\u96c6\u7fa4\u76d1\u63a7\u548c\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u5929\u7136\u7684\u652f\u6301Kubernetes\u548cCoreOS,Kubernete […]<\/p>\n","protected":false},"author":668,"featured_media":142176,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-142175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=142175"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142175\/revisions"}],"predecessor-version":[{"id":142263,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142175\/revisions\/142263"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/142176"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=142175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=142175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=142175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}