{"id":17425,"date":"2025-05-25T18:06:15","date_gmt":"2025-05-25T10:06:15","guid":{"rendered":"https:\/\/92it.top\/?p=17425"},"modified":"2025-06-09T14:51:36","modified_gmt":"2025-06-09T06:51:36","slug":"kubernetesk8s-%e9%83%a8%e7%bd%b2%e4%b8%80%e4%b8%aa%e8%87%aa%e5%b7%b1%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=17425","title":{"rendered":"Kubernetes(k8s) \u90e8\u7f72\u4e00\u4e2a\u81ea\u5df1\u7684\u5e94\u7528"},"content":{"rendered":"\n<p><strong>1.build image\u955c\u50cf<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5728 Kubernetes \u4e2d\u90e8\u7f72\u5e94\u7528\u65f6\uff0c\u6700\u5e38\u7528\u3001\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u662f\u901a\u8fc7<code>image<\/code>\u5b57\u6bb5\u6307\u5b9a\u955c\u50cf\u3002\u6240\u4ee5\u6211\u4eec<\/p>\n\n\n\n<p>\u6839\u636e\u9700\u8981\u81ea\u5df1\u7f16\u8bd1\u4e00\u4e2a<code>image<\/code>\u955c\u50cf\u3002<\/p>\n\n\n\n<ul>\n<li>server.js<\/li>\n<\/ul>\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=\"\">const express = require('express')\nconst query = require('.\/db');\nconst axios = require('axios');\nconst schedule = require('node-schedule');\nconst moment = require('moment');\nconst compression = require('compression');\nconst { v4: uuidv4 } = require('uuid');\n\n\nconst app = express();\n\/\/ \u4f7f\u7528 compression \u4e2d\u95f4\u4ef6\napp.use(compression());\n\/\/ \u89e3\u6790 JSON \u8bf7\u6c42\u4f53\napp.use(express.json());\n\n\u6839\u636e\u4e1a\u52a1\u5177\u4f53\u5b9e\u88c5\n......\n\n\/\/ \u542f\u52a8\u670d\u52a1\u5668\nconst port = 8081;\napp.listen(8081, () => {\n  console.log(`\u670d\u52a1\u5668\u8fd0\u884c\u5728 http:\/\/localhost:${port}`);\n});<\/pre>\n\n\n\n<ul>\n<li>Dockerfile<\/li>\n<\/ul>\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 node:latest\n\n# \u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55\u4e3a \/usr\/src\/app\nRUN mkdir -p \/usr\/src\/app\n\nWORKDIR \/usr\/src\/app\nCOPY . \/usr\/src\/app\n\n# \u66b4\u9732\u5bb9\u5668\u7684 8081 \u7aef\u53e3\nEXPOSE 8081\n\n# \u542f\u52a8 Express \u5e94\u7528\nCMD [\"node\", \"server.js\"]<\/pre>\n\n\n\n<ul>\n<li>\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4build\u955c\u50cf<\/li>\n<\/ul>\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 build --progress=plain -t service-notification .<\/pre>\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=\"\"># \u67e5\u8be2\u521a\u521abuild\u7684 service-notification\u7684 \u955c\u50cfid\ndocker images\n\n# \u7ed9\u955c\u50cf\u6253\u8fdc\u7a0b\u4ed3\u5e93\u7684tag\ndocker tag 5e66f66a0fd0 123.57.154.22:5001\/service-notification:latest<\/pre>\n\n\n\n<ul>\n<li>\u5f80\u8fdc\u7a0b\u4ed3\u5e93\u63a8\u9001\u955c\u50cf<\/li>\n<\/ul>\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 123.57.154.22:5001\/service-notification:latest<\/pre>\n\n\n\n<p><strong>2.\u4fee\u6539docker desktop\u7684\u914d\u7f6e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u56e0\u4e3a\u6211\u642d\u5efa\u7684\u662fhttp\u7684\u955c\u50cf\u79c1\u6709\u4ed3\u5e93\uff0c\u4ece\u522b\u7684docker\u5ba2\u6237\u7aef\u8bbf\u95ee\u62c9\u53d6\u955c\u50cf\uff0c\u662f\u4e0d\u5b89\u5168\uff0c\u88ab\u7981\u6b62\u7684\uff0c\u6240\u4ee5\u9700\u8981\u4fee\u6539 \/Users\/xxx\/.docker\/daemon.json\u6587\u4ef6\uff0c\u6216\u8005\u4ecedocker desktop  UI\u76f4\u63a5\u4fee\u6539\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"573\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-1024x573.png\" alt=\"\" class=\"wp-image-17427\" style=\"width:550px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-1024x573.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-300x168.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-768x430.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-1536x859.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-830x464.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-230x129.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-350x196.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53-480x268.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/05\/image-53.png 1924w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u6dfb\u52a0\u4e0b\u9762\u7684\u914d\u7f6e\uff0c\u7136\u540e\u91cd\u542fdocker<\/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=\"\">\"insecure-registries\": [\n    \"123.57.154.22:5001\"\n  ]<\/pre>\n\n\n\n<p><strong>3.\u5728k8s\u90e8\u7f72\u5e94\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ul>\n<li>\u521b\u5efanamespace<\/li>\n<\/ul>\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 namespace wechat-applet-services<\/pre>\n\n\n\n<ul>\n<li>\u521b\u5efa\u8bbf\u95ee\u79c1\u6709\u4ed3\u5e93\u7684secret<\/li>\n<\/ul>\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 secret docker-registry docker-registry-secret \\\n  --docker-server=123.57.154.22:5001 \\\n  --docker-username=\u79c1\u6709\u4ed3\u5e93username \\\n  --docker-password=\u79c1\u6709\u4ed3\u5e93password \\\n  -n wechat-applet-services<\/pre>\n\n\n\n<ul>\n<li>\u51c6\u5907deployment.yaml<\/li>\n<\/ul>\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=\"\"># service-notification-deployment.yaml\n# kubectl apply -f service-notification-deployment.yaml -n wechat-applet-services\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: service-notification-deployment\n  labels:\n    app: service-notification\nspec:\n  replicas: 1  # \u521b\u5efa1\u4e2aPod\u526f\u672c\n  selector:\n    matchLabels:\n      app: service-notification\n  template:\n    metadata:\n      labels:\n        app: service-notification\n    spec:\n      containers:\n      - name: service-notification\n        image: 123.57.154.22:5001\/service-notification:latest\n        ports:\n        - containerPort: 8081\n        resources:\n          limits:\n            memory: \"128Mi\"\n            cpu: \"100m\"\n      imagePullSecrets:\n      - name: docker-registry-secret<\/pre>\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 apply -f service-notification-deployment.yaml -n wechat-applet-services<\/pre>\n\n\n\n<p>\u7528\u6d4f\u89c8\u5668\u4ecek8s dashboard \u53ef\u4ee5\u770b\u4e0b\u7684\u72b6\u6001<\/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=\"\"># \u521b\u5efa\u4e00\u4e2a\u8bbf\u95eedashboard\u7684token\nkubectl -n kubernetes-dashboard create token admin-user\n\n# \u6d4f\u89c8\u5668\u6253\u5f00\u4e0b\u9762\u7f51\u5740\uff0c\u586b\u5199token\uff0c\u767b\u5f55\nhttp:\/\/localhost:8001\/api\/v1\/namespaces\/kubernetes-dashboard\/services\/https:kubernetes-dashboard:\/proxy\/#\/login<\/pre>\n\n\n\n<p><strong>4.\u5728dashboard\u4e2d\u67e5\u770bPod\u7684\u65e5\u5fd7 \u548c \u8fdb\u5165Pod\u5bb9\u5668<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5728 <strong>dashboard<\/strong> \u4e2d\u67e5\u770b Pod\u65e5\u5fd7<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"522\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-1024x522.png\" alt=\"\" class=\"wp-image-17583\" style=\"width:540px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-1024x522.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-300x153.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-768x391.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-1536x783.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-2048x1043.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-830x423.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-230x117.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-350x178.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-67-480x245.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5728 <strong>dashboard<\/strong> \u4e2d\u8fdb\u5165 Pod \u5bb9\u5668<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"492\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-1024x492.png\" alt=\"\" class=\"wp-image-17585\" style=\"width:538px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-1024x492.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-300x144.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-768x369.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-1536x738.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-2048x984.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-830x399.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-230x111.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-350x168.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-69-480x231.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"516\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-1024x516.png\" alt=\"\" class=\"wp-image-17587\" style=\"width:546px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-1024x516.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-300x151.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-768x387.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-1536x773.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-830x418.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-230x116.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-350x176.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71-480x242.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-71.png 1752w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>","protected":false},"excerpt":{"rendered":"<p>1.build image\u955c\u50cf \u5728 Kubernetes \u4e2d\u90e8\u7f72\u5e94\u7528\u65f6\uff0c\u6700\u5e38\u7528\u3001\u6700\u76f4\u63a5\u7684\u65b9\u5f0f\u662f\u901a\u8fc7image\u5b57 [&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\/17425"}],"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=17425"}],"version-history":[{"count":8,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17425\/revisions"}],"predecessor-version":[{"id":17581,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17425\/revisions\/17581"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}