{"id":590,"date":"2020-09-08T14:50:58","date_gmt":"2020-09-08T06:50:58","guid":{"rendered":"https:\/\/www.yinyubo.cn\/?p=590"},"modified":"2022-05-17T09:30:56","modified_gmt":"2022-05-17T01:30:56","slug":"k8s-3","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=590","title":{"rendered":"\u5728K8S\u91cc\u4f7f\u7528filebeat\u4f5c\u4e3asidecar\u6536\u96c6nginx\u65e5\u5fd7"},"content":{"rendered":"<h1><strong>\u7b80\u4ecb<\/strong><\/h1>\n<p>\u901a\u8fc7sidecar\u65b9\u6cd5\u8fdb\u884c\u63a5\u5165\uff0c\u4e0e\u63d0\u4f9b\u65e5\u5fd7\u7684\u5bb9\u5668\u90e8\u7f72\u5728\u540c\u4e00\u4e2apod\u91cc\uff0c\u4e3b\u8981\u662f\u914d\u7f6estatefulset\u91cc\u7684containers\u548cconfigmap\u91cc\u7684filebeat.yaml<br \/>1.\u628anginx\u7684\u65e5\u5fd7\u6587\u4ef6\u6302\u8f7d\u5728access_log\u8fd9\u4e2avolume\u91cc\uff0c\u540c\u65f6\u5728filebeat\u8fd9\u4e2apod\u91cc\u4e5f\u6302\u8f7daccess_log\u8fd9\u4e2avolume<br \/>2.filebeat\u901a\u8fc7subpath\u7684\u65b9\u6cd5\u6302\u8f7d\u5355\u72ec\u4e00\u4e2afilebeat.yml\u5230\/usr\/share\/filebeat\/filebeat.yml\u3002\u6ce8\u610f\uff0c\u5982\u679c\u4e0d\u7528subpath\u6302\u8f7d\u5355\u4e2a\u6587\u4ef6\u7684\u8bdd\uff0c\u662f\u4f1a\u8986\u76d6\u6389\/usr\/share\/filebeat\/\u76ee\u5f55\u7684<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">3.configmap\u91cc\u8bbe\u7f6eelasticsearch\u7684\u5730\u5740\u548cindex\uff0c\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\n<p>\u00a0<\/p>\n<h3><strong>statefulset.yaml<\/strong><\/h3>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<pre class=\"lang:yaml decode:true EnlighterJSRAW\" title=\"statefulset.yaml\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">containers:\n  - image: nginx:latest\n    name: nginx\n    ports:\n        - containerPort: 80\n    volumeMounts:\n        - name: access-log #\u65e5\u5fd7\u540c\u65f6\u6302\u8f7d\u5728nginx\u548cfilebeat\u4e2d\n          mountPath: \/var\/log\/nginx\/\n  - image: docker.elastic.co\/beats\/filebeat:6.8.12\n    imagePullPolicy: Always\n    name: filebeat\n    volumeMounts:\n        - name: access-log #\u65e5\u5fd7\u540c\u65f6\u6302\u8f7d\u5728nginx\u548cfilebeat\u4e2d\n          mountPath: \/log\n        - name: filebeat-config\n          mountPath: \/usr\/share\/filebeat\/filebeat.yml\n          subPath: filebeat.yml\n  volumes:\n    - name: filebeat-config\n      configMap:\n        name: filebeat-config\n        items:\n        - key: filebeat.yml\n          path: filebeat.yml<\/code><\/pre>\n<h3 class=\"codeHeader panelHeader pdl\"><b>configmap.yaml<\/b><\/h3>\n<div class=\"codeContent panelContent pdl\">\n<div>\n<div id=\"highlighter_558627\" class=\"syntaxhighlighter sh-rdark nogutter yml\">\n<pre class=\"lang:yaml decode:true EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: filebeat-config\ndata:\n  filebeat.yml: |\n    filebeat.inputs:\n    - type: log\n      paths:\n        - \"\/log\/access.log\"\n    setup.template.name: \"filebeat\"\n    setup.template.pattern: \"filebeat-*\"\n    output.elasticsearch:\n      hosts: [\"{{ .Values.elastricsearch.addr }}\"]\n      index: \"frontend-filebeat\"<\/code><\/pre>\n<p>\u00a0<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<h1><strong>\u67b6\u6784\u56fe<\/strong><\/h1>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-591 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-44-1024x729.png\" alt=\"\" width=\"900\" height=\"641\" \/><\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u901a\u8fc7sidecar\u65b9\u6cd5\u8fdb\u884c\u63a5\u5165\uff0c\u4e0e\u63d0\u4f9b\u65e5\u5fd7\u7684\u5bb9\u5668\u90e8\u7f72\u5728\u540c\u4e00\u4e2apod\u91cc\uff0c\u4e3b\u8981\u662f\u914d\u7f6estatefulset\u91cc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-590","post","type-post","status-publish","format-standard","hentry","category-elasticsearch","category-k8s"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=590"}],"version-history":[{"count":1,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/590\/revisions"}],"predecessor-version":[{"id":874,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/590\/revisions\/874"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}