{"id":1427,"date":"2024-03-12T09:59:50","date_gmt":"2024-03-12T01:59:50","guid":{"rendered":"https:\/\/www.yinyubo.com\/?p=1427"},"modified":"2024-03-12T09:59:50","modified_gmt":"2024-03-12T01:59:50","slug":"%e5%9c%a8kubernetes%e9%87%8c%e4%bd%bf%e7%94%a8traefik%e6%8f%92%e4%bb%b6%e5%ae%9e%e7%8e%b0ip%e9%bb%91%e5%90%8d%e5%8d%95%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=1427","title":{"rendered":"\u5728Kubernetes\u91cc\u4f7f\u7528Traefik\u63d2\u4ef6\u5b9e\u73b0IP\u9ed1\u540d\u5355\u529f\u80fd"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p>\u7f51\u4e0a\u5173\u4e8etraefik\u7684ip\u9ed1\u540d\u5355\u529f\u80fd\u7684\u6587\u7ae0\u51e0\u4e4e\u6ca1\u6709\uff0cChatGPT\u8bb2\u89e3\u7684\u4e5f\u4e0d\u592a\u5bf9\uff0c\u4e8e\u662f\u6211\u6839\u636e\u81ea\u5df1\u7684\u4f7f\u7528\u7ecf\u9a8c\u8bb0\u5f55\u4e0b\u5728kubernetes\u91cc\uff0c\u4f7f\u7528traefik\u7684denyip\u63d2\u4ef6\uff0c\u914d\u7f6eIP\u9ed1\u540d\u5355\u529f\u80fd\uff0c\u53ef\u4ee5\u5bf9\u5355\u72ec\u7684ingress(\u57df\u540d)\u751f\u6548\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u6574\u4e2aentrypoint(\u7aef\u53e3)\u751f\u6548<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">traefik\u7684denyip\u5b89\u88c5<\/h2>\n\n\n\n<p>1.\u53bbtraefik\u63d2\u4ef6\u4e2d\u95f4\uff0c\u627e\u5230denyip\u63d2\u4ef6\u7684\u4fe1\u606f<\/p>\n\n\n\n<p><a href=\"https:\/\/plugins.traefik.io\/plugins\/62947363ffc0cd18356a97d1\/deny-ip-plugin\">https:\/\/plugins.traefik.io\/plugins\/62947363ffc0cd18356a97d1\/deny-ip-plugin<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2024\/03\/image-5-1-1024x330.png\" alt=\"\" class=\"wp-image-1428\"\/><\/figure>\n\n\n\n<p>2.\u53c2\u8003traefik\u5b98\u65b9helmchart\u7f16\u5199values-traefik.yaml\u6587\u4ef6(https:\/\/github.com\/traefik\/traefik-helm-chart\/blob\/master\/traefik\/values.yaml)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8fd9\u91cc\u53ea\u8d34\u4e0b\u8f7d\u63d2\u4ef6\u6a21\u5757\u7684\u4ee3\u7801\nexperimental:\n  plugins:\n    denyip:\n      moduleName: github.com\/kevtainer\/denyip\n      version: v1.0.0<\/code><\/pre>\n\n\n\n<p>3.\u5b89\u88c5traefik<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>helm upgrade --install traefik -n traefik -f values-traefik.yaml traefik\/traefik --version 26.0.0<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u5b89\u88c5\u5b8c\u4e4b\u540e\uff0c\u53ef\u4ee5\u68c0\u67e5pod\uff0c\u4f1a\u53d1\u73b0\u5728pod\u914d\u7f6e\u91cc\u6dfb\u52a0\u4e0a\u4e86\u63d2\u4ef6\u4fe1\u606f\nkubectl describe pod -n traefik traefik-txxqm<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2024\/03\/Image-2-1-1.png\" alt=\"\" class=\"wp-image-1429\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bf9\u6574\u4e2aentrypoint\u9650\u5236IP\u8bbf\u95ee\uff08\u4f8b\u5982\u9650\u5236IP\u8bbf\u95ee80\u7aef\u53e3\u4e0b\u7684\u6240\u6709\u57df\u540d\uff09<\/h2>\n\n\n\n<p>1.\u6dfb\u52a0middleware.yaml\u6587\u4ef6\uff0c\u4f8b\u5982\u7981\u7528192.168.1.1\u7684IP\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: traefik.containo.us\/v1alpha1\nkind: Middleware\nmetadata:\n    name: denyip\n    namespace: traefik\nspec:\n    plugin:\n        denyip:\n            ipDenyList:\n                - 192.168.1.1<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u5b8c\u540e\uff0c\u4f7f\u7528kubectl apply -f middleware.yaml\u547d\u4ee4\u4f7f\u5176\u751f\u6548<\/p>\n\n\n\n<p>2.\u7f16\u8f91values-traefik.yaml\u6587\u4ef6\uff0c\u4fee\u6539ports\u90e8\u5206\uff0c\u627e\u523080\u7aef\u53e3\u90e8\u5206\uff0c\u4fee\u6539\u4ee3\u7801\u5982\u4e0b\uff0c\u53ea\u751f\u6548\u4e8e80\u7aef\u53e3\uff0c443\u7aef\u53e3\u4e0d\u751f\u6548\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ports:\n  web:\n    port: 80\n    expose: true\n    exposedPort: 80 # \u5bf9\u5916\u7684 HTTP \u7aef\u53e3\u53f7\uff0c\u4f7f\u7528\u6807\u51c6\u7aef\u53e3\u53f7\u5728\u56fd\u5185\u9700\u5907\u6848\n    middlewares:\n     - traefik-denyip@kubernetescrd\n  websecure:\n    port: 443\n    expose: true\n    exposedPort: 443 # \u5bf9\u5916\u7684 HTTPS \u7aef\u53e3\u53f7\uff0c\u4f7f\u7528\u6807\u51c6\u7aef\u53e3\u53f7\u5728\u56fd\u5185\u9700\u5907\u6848<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2024\/03\/Image-3-1-1.png\" alt=\"\" class=\"wp-image-1432\"\/><\/figure>\n\n\n\n<p>3.\u518d\u6b21\u5b89\u88c5traeifk<\/p>\n\n\n\n<p>helm upgrade &#8211;install traefik -n traefik -f values-traefik.yaml traefik\/traefik &#8211;version 26.0.0<\/p>\n\n\n\n<p>4,\u53bbdashboard\u9875\u9762\u68c0\u67e5\uff0c\u4f1a\u53d1\u73b0\u5728\u8fd9\u4e2aentrypoint\u7684\u6240\u6709ingress\u7684\u914d\u7f6e\u91cc\uff0c\u90fd\u4f1a\u52a0\u4e0a\u8be5middleware<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2024\/03\/image-5-1-1-1024x641.png\" alt=\"\" class=\"wp-image-1433\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bf9\u5355\u4e00IngressRoute\u751f\u6548(\u4f8b\u5982\u5bf9\u6307\u5b9a\u57df\u540d\u6216\u8def\u5f84)<\/h2>\n\n\n\n<p>1.\u6dfb\u52a0middleware.yaml\u6587\u4ef6\uff0c\u4f8b\u5982\u7981\u7528192.168.1.1\u7684IP\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: traefik.containo.us\/v1alpha1\nkind: Middleware\nmetadata:\n    name: denyip\n    namespace: traefik\nspec:\n    plugin:\n        denyip:\n            ipDenyList:\n                - 192.168.1.1<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u5b8c\u540e\uff0c\u4f7f\u7528kubectl apply -f middleware.yaml\u547d\u4ee4\u4f7f\u5176\u751f\u6548<\/p>\n\n\n\n<p>2.\u8fd9\u91cc\u6709\u4e00\u4e2a\u6ce8\u610f\u70b9\uff0c\u5f80\u5f80\u6211\u4eec\u7684ingress\u548cmiddleware\u4e0d\u4e00\u5b9a\u5728\u540c\u4e00\u4e2anamespace\uff0c\u8fd9\u4e2a\u65f6\u5019\u9700\u8981\u5728\u5b89\u88c5traefik\u7684\u65f6\u5019\u542f\u7528\u3010\u5141\u8bb8\u4f7f\u7528\u8de8\u547d\u540d\u7a7a\u95f4\u3011\u529f\u80fd\uff0c\u4fee\u6539values-traefik.yaml\uff0c\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>providers:\n  kubernetesCRD:\n    allowCrossNamespace: true<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u518d\u6b21\u5b89\u88c5 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>helm upgrade --install traefik -n traefik -f values-traefik.yaml traefik\/traefik --version 26.0.0<\/code><\/pre>\n\n\n\n<p>3.\u4fee\u6539\u9700\u8981\u4f7f\u7528middleware\u7684ingressroute\u6587\u4ef6\uff0c\u548cservice\u540c\u7ea7\u589e\u52a0middlewares\u4fe1\u606f<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2024\/03\/image-5-4-1-1.png\" alt=\"\" class=\"wp-image-1434\"\/><\/figure>\n\n\n\n<p>4.\u4fee\u6539\u5b8c\u6210\u540e\uff0c\u518d\u53bbdashboard\u9875\u9762\u68c0\u67e5\uff0c\u4f1a\u53d1\u73b0\u53ea\u6709\u8be5http route\u6709middleware\u4fe1\u606f\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u57df\u540d\u7684\u6b63\u5e38\u8bbf\u95ee<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u7f51\u4e0a\u5173\u4e8etraefik\u7684ip\u9ed1\u540d\u5355\u529f\u80fd\u7684\u6587\u7ae0\u51e0\u4e4e\u6ca1\u6709\uff0cChatGPT\u8bb2\u89e3\u7684\u4e5f\u4e0d\u592a\u5bf9\uff0c\u4e8e\u662f\u6211\u6839\u636e\u81ea\u5df1\u7684\u4f7f\u7528 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1427","post","type-post","status-publish","format-standard","hentry","category-k8s"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1427","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=1427"}],"version-history":[{"count":0,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1427\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}