{"id":11785,"date":"2023-08-12T22:06:30","date_gmt":"2023-08-12T14:06:30","guid":{"rendered":"http:\/\/92it.top\/?p=11785"},"modified":"2023-08-18T09:28:25","modified_gmt":"2023-08-18T01:28:25","slug":"asp-net-core-on-k8s%e5%ad%a6%e4%b9%a0%e5%88%9d%e6%8e%a2-%e9%83%a8%e7%bd%b2api%e5%88%b0k8s","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11785","title":{"rendered":"ASP.NET Core on K8S\u5b66\u4e60\u521d\u63a2 \u90e8\u7f72API\u5230K8S"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_on_k8s_firststudy_part3.html\">https:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_on_k8s_firststudy_part3.html<\/a><\/p>\n\n\n\n<p><strong>\u4e00\u3001\u51c6\u5907\u4e00\u4e2aWebAPI<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u8fd9\u91cc\u51c6\u5907\u4e00\u4e2a\u7a7a\u7684ASP.NET Core WebAPI\u9879\u76ee\uff0c\u4f7f\u7528\u9ed8\u8ba4\u81ea\u5e26\u7684ValuesController\u63a7\u5236\u5668\uff0c\u5177\u4f53\u4ee3\u7801\u89c1<a href=\"https:\/\/github.com\/EdisonChou\/AspNetCore.On.K8S\/tree\/master\/src\/01_hello-k8s\/EDC.K8S.Demo.WebApi\" target=\"_blank\" rel=\"noreferrer noopener\">\u8fd9\u91cc<\/a>\u3002<\/p>\n\n\n\n<p>Dockerfile\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">FROM microsoft\/dotnet:2.1-aspnetcore-runtime AS base\nWORKDIR \/app\nEXPOSE 80\n\nFROM microsoft\/dotnet:2.1-sdk AS build\nWORKDIR \/src\nCOPY . .\n\nRUN dotnet restore\nRUN dotnet build -c Release -o \/app\n\nFROM build AS publish\nRUN dotnet publish -c Release -o \/app\n\nFROM base AS final\nWORKDIR \/app\nCOPY --from=publish \/app .\nENTRYPOINT [\"dotnet\", \"EDC.K8S.Demo.WebApi.dll\"]<\/pre>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4e8b\u5148\u5728\u81ea\u5df1\u7684Docker\u73af\u5883\u6784\u5efa\u8fd9\u6837\u7684\u4e00\u4e2a\u955c\u50cf\uff0c\u770b\u770b\u80fd\u5426\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u540e\u9762\u4f1a\u4f7f\u7528\u5230\u8fd9\u4e2a\u955c\u50cf\uff0c\u56e0\u6b64\u53ef\u4ee5\u5c06\u6b64\u955c\u50cfpush\u5230<a rel=\"noreferrer noopener\" href=\"https:\/\/hub.docker.com\" target=\"_blank\">Docker Hub<\/a>\u4e0a\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker push your-image-name:tagname<\/pre>\n\n\n\n<p>\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u6211\u4e0a\u4f20\u7684\u8fd9\u4e2a\u955c\u50cf\uff08edisonsaonian\/k8s-demo\uff09\u3002<\/p>\n\n\n\n<p><strong>\u4e8c\u3001\u90e8\u7f72WebAPI\u5230K8S<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>2.1 \u51c6\u5907Deployment YAML<\/strong><\/p>\n\n\n\n<p>\u5728\u4e0a\u4e00\u7bc7\u4e2d\u6211\u4eec\u77e5\u9053Deployment\u4e3b\u8981\u8d1f\u8d23Pod\u7684\u7f16\u6392\uff0c\u90a3\u4e48\u6211\u4eec\u8fd9\u91cc\u5c31\u901a\u8fc7\u4e00\u4e2aYAML\u6765\u521b\u5efa\u4e00\u4e2aDeployment\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: k8s-demo\n  namespace: aspnetcore\n  labels:\n    name: k8s-demo\nspec:\n  replicas: 2\n  selector:\n    matchLabels:\n      name: k8s-demo\n  template:\n    metadata:\n      labels:\n        name: k8s-demo\n    spec:\n      containers:\n      - name: k8s-demo\n        image: edisonsaonian\/k8s-demo\n        ports:\n        - containerPort: 80\n        imagePullPolicy: Always\n\n---\n\nkind: Service\napiVersion: v1\nmetadata:\n  name: k8s-demo\n  namespace: aspnetcore\nspec:\n  type: NodePort\n  ports:\n    - port: 80\n      targetPort: 80\n  selector:\n    name: k8s-demo<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u8fd9\u4e2adeploy.yaml\u5c31\u4f1a\u544a\u8bc9K8S\u5173\u4e8e\u4f60\u7684API\u7684\u6240\u6709\u4fe1\u606f\uff0c\u4ee5\u53ca\u901a\u8fc7\u4ec0\u4e48\u6837\u7684\u65b9\u5f0f\u66b4\u9732\u51fa\u6765\u8ba9\u5916\u90e8\u8bbf\u95ee\u3002<\/p>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u91cc\u6211\u4eec\u63d0\u524d\u4e3a\u8981\u90e8\u7f72\u7684ASP.NET Core WebAPI\u9879\u76ee\u521b\u5efa\u4e86\u4e00\u4e2anamespace\uff0c\u53eb\u505aaspnetcore\uff0c\u56e0\u6b64\u8fd9\u91cc\u5199\u7684namespace : aspnetcore\u3002<\/p>\n\n\n\n<p>K8S\u4e2d\u901a\u8fc7\u6807\u7b7e\u6765\u533a\u5206\u4e0d\u540c\u7684\u670d\u52a1\uff0c\u56e0\u6b64\u8fd9\u91cc\u7edf\u4e00name\u5199\u6210\u4e86k8s-demo\u3002<\/p>\n\n\n\n<p>\u5728\u591a\u5b9e\u4f8b\u7684\u914d\u7f6e\u4e0a\uff0c\u901a\u8fc7replicas : 2\u8fd9\u4e2a\u8bbe\u7f6e\u544a\u8bc9K8S\u7ed9\u6211\u542f\u52a82\u4e2a\u5b9e\u4f8b\u8d77\u6765\uff0c\u5f53\u7136\u4f60\u53ef\u4ee5\u5199\u66f4\u5927\u7684\u4e00\u4e2a\u6570\u91cf\u503c\u3002<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u5728spec\u4e2d\u544a\u8bc9K8S\u6211\u8981\u901a\u8fc7NodePort\u7684\u65b9\u5f0f\u66b4\u9732\u51fa\u6765\u516c\u5f00\u8bbf\u95ee\uff0c\u56e0\u6b64\u7aef\u53e3\u8303\u56f4\u4ece\u4e0a\u4e00\u7bc7\u53ef\u4ee5\u77e5\u9053\uff0c\u5e94\u8be5\u662f 30000-32767\u8fd9\u4e2a\u8303\u56f4\u4e4b\u5185\u3002<\/p>\n\n\n\n<p><strong>2.2 \u901a\u8fc7kubectl\u90e8\u7f72\u5230K8S<\/strong><\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Docker for Windows\u4ee5\u53caKubernetes\u90fd\u542f\u52a8\u8d77\u6765\u4e86\u3002<\/p>\n\n\n\n<p>\u7136\u540e\uff0c\u5728Powershell\u4e2d\u901a\u8fc7kubectl\u5b8c\u6210API\u7684\u90e8\u7f72\uff0c\u53ea\u9700\u8981\u4e0b\u9762\u8fd9\u4e00\u53e5\u547d\u4ee4\u884c\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl create -f deploy.yaml<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-1024x88.png\" alt=\"\" class=\"wp-image-11786\" width=\"524\" height=\"45\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-1024x88.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-300x26.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-768x66.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-830x71.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-230x20.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-350x30.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97-480x41.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-97.png 1210w\" sizes=\"(max-width: 524px) 100vw, 524px\" \/><\/figure><\/div>\n\n\n\n<p>\u770b\u5230\u4e0a\u9762\u7684\u63d0\u793a&#8221;service created&#8221;\uff0c\u5c31\u53ef\u4ee5\u77e5\u9053\u5df2\u7ecf\u521b\u5efa\u597d\u4e86\uff0c\u8fd9\u91cc\u6211\u4eec\u518d\u901a\u8fc7\u4e0b\u9762\u8fd9\u4e2a\u547d\u4ee4\u6765\u9a8c\u8bc1\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl get svc -n aspnetcore<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-1024x89.png\" alt=\"\" class=\"wp-image-11787\" width=\"542\" height=\"47\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-1024x89.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-300x26.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-768x67.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-830x72.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-230x20.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-350x31.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98-480x42.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-98.png 1216w\" sizes=\"(max-width: 542px) 100vw, 542px\" \/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u547d\u540d\u7a7a\u95f4aspnetcore\u4e0b\uff0c\u5c31\u6709\u4e86\u4e00\u4e2ak8s-demo\u7684\u670d\u52a1\u8fd0\u884c\u8d77\u6765\u4e86\uff0c\u5e76\u901a\u8fc7\u7aef\u53e3\u53f731435\u5411\u5916\u90e8\u63d0\u4f9b\u8bbf\u95ee\u3002<\/p>\n\n\n\n<p><strong>2.3 \u5728K8S\u4e2d\u9a8c\u8bc1WebAPI<\/strong><\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u6765\u8bbf\u95ee\u4e00\u4e0b\u8fd9\u4e2aAPI\u63a5\u53e3\uff0c\u770b\u770b\u662f\u5426\u80fd\u6b63\u5e38\u8bbf\u95ee\u5230\u3002<\/p>\n\n\n\n<ul><li>\/api\/values<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-1024x143.png\" alt=\"\" class=\"wp-image-11788\" width=\"589\" height=\"82\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-1024x143.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-300x42.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-768x107.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-830x116.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-230x32.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-350x49.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99-480x67.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-99.png 1218w\" sizes=\"(max-width: 589px) 100vw, 589px\" \/><\/figure><\/div>\n\n\n\n<ul><li>\/api\/values\/1000<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-1024x327.png\" alt=\"\" class=\"wp-image-11789\" width=\"455\" height=\"145\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-1024x327.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-300x96.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-768x245.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-830x265.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-230x73.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-350x112.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100-480x153.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-100.png 1222w\" sizes=\"(max-width: 455px) 100vw, 455px\" \/><\/figure><\/div>\n\n\n\n<p>\u5176\u6b21\uff0c\u8fd8\u8bb0\u5f97\u5728\u7b2c\u4e00\u7bc7\u4e2d\u90e8\u7f72\u7684Dashboard\u5417\uff1f\u6211\u4eec\u901a\u8fc7Dashboard\u6765\u770b\u770b\u6211\u4eec\u7684k8s-demo\u7684\u72b6\u6001\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-926x1024.png\" alt=\"\" class=\"wp-image-11790\" width=\"513\" height=\"567\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-926x1024.png 926w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-271x300.png 271w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-768x849.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-830x918.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-230x254.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-350x387.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101-480x531.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-101.png 1384w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/figure><\/div>\n\n\n\n<p>\u4eceDashboard\u4e2d\u53ef\u4ee5\u770b\u5230\u66f4\u4e3a\u8be6\u7ec6\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u8fd0\u884c\u7684Deployment\u3001\u5bb9\u5668\u7ec4\uff08\u7531\u4e8e\u6211\u4eec\u8bbe\u7f6e\u7684replicas=2\uff0c\u56e0\u6b64\u4f1a\u67092\u4e2a\u5bb9\u5668\u8fd0\u884c\u8d77\u6765\uff09\u3001\u526f\u672c\u96c6\u7b49\u7b49\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7Dashboard\u5b9e\u65f6\u521d\u6b65\u5730\u76d1\u63a7\u6211\u4eec\u7684API\u7684\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n\n\n\n<p><strong>\u4e09\u3001\u5728K8S\u4e2d\u5bf9WebAPI\u7684\u4f38\u7f29<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>3.1 \u901a\u8fc7Dashboard\u4f38\u7f29WebAPI<\/strong><\/p>\n\n\n\n<p>\u5728Dashboard\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u53ef\u89c6\u5316\u5730\u5bf9\u6211\u4eec\u7684Deployment\u8fdb\u884c\u5bb9\u5668\u5b9e\u4f8b\u7684\u4f38\u7f29\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-1024x381.png\" alt=\"\" class=\"wp-image-11793\" width=\"543\" height=\"201\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-1024x381.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-300x112.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-768x286.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-830x309.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-230x86.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-350x130.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102-480x179.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-102.png 1220w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u5f39\u51fa\u7684\u4f38\u7f29\u9009\u9879\u5bf9\u8bdd\u6846\u4e2d\u8f93\u5165\u4e2a\u6570\uff0c\u4f8b\u5982\u6211\u4eec\u8fd9\u91cc\u4ece2\u4e2a\u7f29\u51cf\u4e3a1\u4e2a\uff0c\u7136\u540e\u786e\u5b9a\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-103.png\" alt=\"\" class=\"wp-image-11794\" width=\"347\" height=\"386\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-103.png 646w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-103-270x300.png 270w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-103-230x256.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-103-350x389.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-103-480x533.png 480w\" sizes=\"(max-width: 347px) 100vw, 347px\" \/><\/figure><\/div>\n\n\n\n<p>\u518d\u6b21\u89c2\u770bDashboard\uff0c\u53ef\u4ee5\u770b\u5230\u5df2\u7ecf\u4ece\u539f\u6765\u76842\u4e2a\u5bb9\u5668\u5b9e\u4f8b\u53d8\u4e3a1\u4e2a\u4e86\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-1024x508.png\" alt=\"\" class=\"wp-image-11795\" width=\"540\" height=\"267\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-1024x508.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-300x149.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-768x381.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-830x411.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-230x114.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-350x173.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104-480x238.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-104.png 1372w\" sizes=\"(max-width: 540px) 100vw, 540px\" \/><\/figure><\/div>\n\n\n\n<p><strong>3.2 \u901a\u8fc7Kubectl\u4f38\u7f29WebAPI<\/strong><\/p>\n\n\n\n<p>\u9664\u4e86\u5728Dashboard\u4e2d\u53ef\u89c6\u5316\u5730\u64cd\u4f5c\u8fdb\u884c\u4f38\u7f29\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7kubectl\u6765\u8fdb\u884c\uff0c\u4f8b\u5982\u4e0b\u9762\u8fd9\u53e5\u547d\u4ee4\uff0c\u5c06\u5bb9\u5668\u5b9e\u4f8b\u6269\u5c55\u52303\u4e2a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u6211\u4eec\u7684k8s-demo\u6240\u5728\u7684\u547d\u540d\u7a7a\u95f4\u662f\u5728aspnetcore\u4e0b\uff0c\u56e0\u6b64\u4e5f\u9700\u8981\u6307\u660e&#8211;namespace=aspnetcore\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl scale deployment k8s-demo --replicas=3 --namespace=aspnetcore<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-1024x83.png\" alt=\"\" class=\"wp-image-11796\" width=\"638\" height=\"52\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-1024x83.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-300x24.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-768x62.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-830x67.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-230x19.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-350x28.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105-480x39.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-105.png 1214w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/figure><\/div>\n\n\n\n<p>\u518d\u5230Dashboard\u4e2d\u6765\u9a8c\u8bc1\u4e00\u4e0b\uff0c\u662f\u5426\u6269\u5c55\u5230\u4e863\u4e2a\u5bb9\u5668\u5b9e\u4f8b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-1024x273.png\" alt=\"\" class=\"wp-image-11797\" width=\"614\" height=\"163\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-1024x273.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-300x80.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-768x204.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-830x221.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-230x61.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-350x93.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106-480x128.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-106.png 1390w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><\/figure><\/div>\n\n\n\n<p><strong>3.3 \u81ea\u52a8\u4f38\u7f29WebAPI\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n<p>\u5728K8S\u4e2d\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2aautoscale\u63a5\u53e3\u6765\u5b9e\u73b0\u670d\u52a1\u7684\u81ea\u52a8\u4f38\u7f29\uff0c\u5b83\u4f1a\u91c7\u7528\u9ed8\u8ba4\u7684\u81ea\u52a8\u4f38\u7f29\u7b56\u7565\uff08\u4f8b\u5982\u6839\u636eCPU\u7684\u8d1f\u8f7d\u60c5\u51b5\uff09\u6765\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u5f39\u6027\u4f38\u7f29\u7684\u529f\u80fd\u3002\u4f8b\u5982\u4e0b\u9762\u8fd9\u53e5\u547d\u4ee4\u53ef\u4ee5\u5b9e\u73b0\u6211\u4eec\u7684k8s-demo\u53ef\u4ee5\u4f38\u7f29\u7684\u8303\u56f4\u662f1~3\u4e2a\uff0c\u6839\u636e\u8d1f\u8f7d\u60c5\u51b5\u81ea\u5df1\u4f38\u7f29\uff0c\u5728\u6ca1\u6709\u591a\u5c11\u8bf7\u6c42\u91cf\u538b\u529b\u5f88\u5c0f\u65f6\u6536\u7f29\u4e3a\u4e00\u4e2a\uff0c\u5728\u538b\u529b\u8f83\u5927\u65f6\u542f\u52a8\u53e6\u4e00\u4e2a\u5b9e\u4f8b\u6765\u964d\u4f4e\u8d1f\u8f7d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl autoscale deployment k8s-demo --min=1 --max=3 --namespace=aspnetcore<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107-1024x67.png\" alt=\"\" class=\"wp-image-11798\" width=\"662\" height=\"42\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107-1024x67.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107-300x20.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107-768x50.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107-230x15.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107-350x23.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-107.png 1218w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u56db\u3001\u8865\u5145\u77e5\u8bc6\u70b9<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>4.1 \u5e38\u7528Kubectl\u547d\u4ee4<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl get svc -n kube-system  \/\/\u83b7\u53d6\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u7684\u670d\u52a1\nkubectl cluster-info \/\/ \u83b7\u53d6\u96c6\u7fa4\u4fe1\u606f\nkubectl get nodes \/\/ \u83b7\u53d6\u96c6\u7fa4\u8282\u70b9\u4fe1\u606f\nkubectl delete node 192.168.2.152  \/\/\u5220\u9664\u8282\u70b9 192.168.2.152\nkubectl get namespaces \/\/ \u83b7\u53d6\u6240\u6709\u547d\u540d\u7a7a\u95f4\nkubectl create namespace aspnetcore \/\/ \u521b\u5efa\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4\u201caspnetcore\u201d<\/pre>\n\n\n\n<p>\u3000\u66f4\u591akubectl\u547d\u4ee4\u53c2\u8003\uff1a<\/p>\n\n\n\n<p>\uff081\uff09<a rel=\"noreferrer noopener\" href=\"https:\/\/jimmysong.io\/kubernetes-handbook\/guide\/kubectl-cheatsheet.html\" target=\"_blank\">https:\/\/jimmysong.io\/kubernetes-handbook\/guide\/kubectl-cheatsheet.html<\/a><\/p>\n\n\n\n<p>\uff082\uff09<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jianshu.com\/p\/fb5c0d115421\" target=\"_blank\">https:\/\/www.jianshu.com\/p\/fb5c0d115421<\/a><\/p>\n\n\n\n<p><strong>4.2 YAML\u6587\u4ef6\u89e3\u6790<\/strong><\/p>\n\n\n\n<p>\u5173\u4e8eYAML\u6587\u4ef6\u5404\u4e2a\u8282\u70b9\u7684\u89e3\u91ca\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u8fd9\u4e2a\u547d\u4ee4\u53bb\u4e86\u89e3\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl explain deployment.metadata<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-1024x458.png\" alt=\"\" class=\"wp-image-11799\" width=\"496\" height=\"221\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-1024x458.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-300x134.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-768x344.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-830x371.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-230x103.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-350x157.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108-480x215.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-108.png 1234w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/figure><\/div>\n\n\n\n<p>\u66f4\u591aYAML\u6587\u4ef6\u7684\u8282\u70b9\u53c2\u8003\uff1a<a href=\"https:\/\/www.kubernetes.org.cn\/1414.html\">https:\/\/www.kubernetes.org.cn\/1414.html<\/a><\/p>\n\n\n\n<p><strong>4.3 \u66f4\u591aK8S\u57fa\u7840\u77e5\u8bc6\uff1f<\/strong><\/p>\n\n\n\n<p>\u63a8\u8350\u9605\u8bfb\u300a<a rel=\"noreferrer noopener\" href=\"http:\/\/www.ijiandao.com\/2b\/baijia\/290521.html\" target=\"_blank\">18\u5f20\u63d2\u753b\u4e86\u89e3Kubernetes\u80cc\u666f\u4e0e\u6982\u5ff5<\/a>\u300b<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109.png\" alt=\"\" class=\"wp-image-11800\" width=\"547\" height=\"363\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109.png 878w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109-300x200.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109-768x511.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109-830x552.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109-230x153.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109-350x233.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-109-480x319.png 480w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u4e94\u3001\u5c0f\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u672c\u6587\u7b80\u5355\u7684\u4ecb\u7ecd\u4e86\u4e00\u4e0b\u5728Docker for Windows\u73af\u5883\u4e0b\uff0c\u901a\u8fc7kubectl\u90e8\u7f72\u4e00\u4e2aASP.NET Core WebAPI\u5230K8S\u4e2d\uff0c\u5e76\u521d\u6b65\u4f7f\u7528\u4e86K8S\u7684\u4f38\u7f29\u7279\u6027\u5bf9Deployment\u8fdb\u884c\u5b9e\u4f8b\u7684\u4f38\u7f29\uff0c\u4f53\u9a8c\u4e86\u4e00\u4e0b\u6240\u8c13\u7684\u5bb9\u5668\u7684\u7f16\u6392\u3002\u5f53\u7136\uff0c\u7b14\u8005\u4e5f\u662f\u521d\u73a9\uff0c\u6709\u5f88\u591a\u8fd8\u6ca1\u5b66\u4e60\uff0c\u8fd9\u4e5f\u53ea\u662fK8S\u7684\u51b0\u5c71\u4e00\u89d2\uff0c\u540e\u7eed\u6211\u4f1a\u5b66\u4e60\u5728Linux\u4e0b\u90e8\u7f72K8S\u7684\u751f\u4ea7\u7ea7\u96c6\u7fa4\u73af\u5883\uff0c\u6df1\u5165\u5b66\u4e60K8S\u7684\u5404\u79cd\u6982\u5ff5\u5e76\u5b9e\u8df5\uff0c\u6700\u540e\u4f1a\u5b66\u4e60\u963f\u91cc\u4e91ACK\u670d\u52a1\uff08\u5bb9\u5668\u670d\u52a1Kubernetes\u7248\uff09\u6216\u817e\u8baf\u4e91TKE\u670d\u52a1\uff08\u57fa\u4e8eKubernetes\u7684\u5bb9\u5668\u670d\u52a1\uff09\u53bb\u90e8\u7f72\u548c\u5b9e\u8df5\u516c\u53f8\u7684\u751f\u4ea7\u73af\u5883\uff0c\u76f8\u4fe1\u5230\u65f6\u4e5f\u4f1a\u6709\u5f88\u591a\u7684\u5206\u4eab\u7684\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttps:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_on_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11785"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11785"}],"version-history":[{"count":4,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11785\/revisions"}],"predecessor-version":[{"id":11927,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11785\/revisions\/11927"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}