{"id":18169,"date":"2025-06-27T21:40:12","date_gmt":"2025-06-27T13:40:12","guid":{"rendered":"https:\/\/92it.top\/?p=18169"},"modified":"2025-08-19T10:37:34","modified_gmt":"2025-08-19T02:37:34","slug":"kubernetesk8s-%e9%83%a8%e7%bd%b2%e5%ba%94%e7%94%a8pv%e3%80%81pvc","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=18169","title":{"rendered":"Kubernetes(k8s) \u90e8\u7f72\u5e94\u7528(PV\u3001PVC)\ud83c\udf00"},"content":{"rendered":"\n<p>\u6709\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u540e\u7aef\u670d\u52a1\uff0c\u539f\u6765\u6258\u7ba1\u5728\u963f\u91cc\u4e91\u4e0a\uff0c\u73b0\u5728\u5e0c\u671b\u505a\u6210\u5fae\u670d\u52a1\u53d1\u5e03\u5728k8s\u4e0a\u3002<\/p>\n\n\n\n<p><strong>1.\u914d\u7f6e nginx \u5bb9\u5668\uff0c\u8f6c\u53d1HTTPS \u8bf7\u6c42\uff08\u914d\u7f6e\u6709SSL\u8bc1\u4e66\uff09\u5230k8s<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\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 run -d  --name nginx  -p 8081:8081  -v \/mnt\/nginx\/logs:\/var\/log\/nginx -v \/mnt\/nginx\/conf.d:\/etc\/nginx\/conf.d  -v \/mnt\/nginx\/certs:\/etc\/nginx\/certs  nginx:alpine<\/pre>\n\n\n\n<p>\u5728 \/mnt\/nginx\/certs \u76ee\u5f55\u4e0b\u653e\u7f6eSSL\u8bc1\u4e66<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"566\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-451.png\" alt=\"\" class=\"wp-image-18170\" style=\"width:322px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-451.png 604w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-451-300x281.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-451-230x216.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-451-350x328.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-451-480x450.png 480w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/figure><\/div>\n\n\n<p>\u5728 \/mnt\/nginx\/conf.d \u76ee\u5f55\u4e0b\u653e\u7f6enginx\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"584\" height=\"478\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-452.png\" alt=\"\" class=\"wp-image-18171\" style=\"width:320px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-452.png 584w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-452-300x246.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-452-230x188.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-452-350x286.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-452-480x393.png 480w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/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=\"\">server {\n    listen 8081 ssl;\n    server_name 92it.top www.92it.top;  # \u540c\u65f6\u652f\u6301\u4e24\u79cd\u57df\u540d\u8bbf\u95ee\n\n    # \u5141\u8bb8\u6700\u5927\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u4e3a 100MB\n    client_max_body_size 100M;\n    client_body_buffer_size 256k;\n\n\n    # \u4ee3\u7406\u8d85\u65f6\u914d\u7f6e\n    proxy_connect_timeout 120s;  # \u8fde\u63a5\u540e\u7aef\u670d\u52a1\u5668\u7684\u8d85\u65f6\u65f6\u95f4\n    proxy_send_timeout 300s;     # \u5411\u540e\u7aef\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\n    proxy_read_timeout 600s;     # \u4ece\u540e\u7aef\u670d\u52a1\u5668\u8bfb\u53d6\u54cd\u5e94\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u5173\u952e\u53c2\u6570\uff09\n\n    # SSL \u8bc1\u4e66\u914d\u7f6e\n    ssl_certificate \/etc\/nginx\/certs\/ssl-cert.pem;\n    ssl_certificate_key \/etc\/nginx\/certs\/ssl-cert.key;\n\n    # \u8f6c\u53d1\u6240\u6709\u8bf7\u6c42\u5230\u76ee\u6807\u4e3b\u673a\n    location \/ {\n        proxy_pass http:\/\/123.56.xxx.xxx:30080; \u8f6c\u53d1\u6240\u6709\u8bf7\u6c42\u5230\u8fd9\u4e2aip\u5730\u5740\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n\n        # \u53ef\u9009\uff1a\u4fdd\u7559\u6240\u6709\u8bf7\u6c42\u5934\u90e8\uff08\u5305\u62ec\u975e\u6807\u51c6\u5b57\u6bb5\uff09\n        proxy_pass_request_headers on;\n    }\n}<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>2.\u5728k8s \u901a\u8fc7 kubectl \u547d\u4ee4 \u505a\u6210pv<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5728 Kubernetes\uff08K8S\uff09\u91cc\uff0cPV\uff08Persistent Volume\uff0c\u6301\u4e45\u5377 \uff09\u548c PVC\uff08PersistentVolumeClaim\uff0c\u6301\u4e45\u5377\u58f0\u660e \uff09\u662f\u5b9e\u73b0<strong>\u5bb9\u5668\u6301\u4e45\u5316\u5b58\u50a8<\/strong>\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u7528\u4e8e\u89e3\u8026\u5b58\u50a8\u8d44\u6e90\u7684 \u201c\u4f9b\u7ed9\u201d \u548c \u201c\u4f7f\u7528\u201d\u3002<\/p>\n\n\n\n<ul>\n<li>\u5b9a\u4e49\uff1aPV \u662f\u96c6\u7fa4\u91cc\u7684\u4e00\u5757\u7f51\u7edc\u5b58\u50a8\u8d44\u6e90\uff0c\u7531\u7ba1\u7406\u5458\u521b\u5efa\u6216\u901a\u8fc7\u5b58\u50a8\u7c7b\u52a8\u6001\u521b\u5efa\uff0c\u72ec\u7acb\u4e8e Pod \u5b58\u5728\uff0c\u53ef\u770b\u4f5c\u96c6\u7fa4\u7ea7\u522b\u7684 \u201c\u5b58\u50a8\u8d44\u6e90\u6c60<strong>\u201d<\/strong>&nbsp;\u3002<br>\u7c7b\u6bd4\uff1a\u628a PV \u60f3\u6210 \u201c\u5171\u4eab\u786c\u76d8\u201d\uff0c\u63d0\u524d\u63a5\u5165 K8S \u96c6\u7fa4\uff0c\u4f9b Pod \u6309\u9700\u4f7f\u7528\u3002<\/li>\n\n\n\n<li>\u4f5c\u7528\uff1a\n<ul>\n<li>\u62bd\u8c61\u5e95\u5c42\u5b58\u50a8\u7ec6\u8282\uff08\u4e0d\u7ba1\u662f\u4e91\u5382\u5546\u5b58\u50a8\u3001NFS\u3001iSCSI \u8fd8\u662f\u672c\u5730\u5b58\u50a8\uff0c\u5bf9\u7528\u6237\u7edf\u4e00\u66b4\u9732\u4e3a PV \uff09\u3002<\/li>\n\n\n\n<li>\u4f5c\u4e3a \u201c\u516c\u5171\u5b58\u50a8\u8d44\u6e90\u201d\uff0c\u88ab\u591a\u4e2a Pod \u5171\u4eab\u6216\u72ec\u5360\uff0c\u751f\u547d\u5468\u671f\u72ec\u7acb\u4e8e\u5355\u4e2a Pod\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5173\u952e\u5c5e\u6027\uff1a\n<ul>\n<li>\u5bb9\u91cf\uff1a\u5982&nbsp;<code>10Gi<\/code>\uff0c\u6307\u5b9a\u5b58\u50a8\u5927\u5c0f\u3002<\/li>\n\n\n\n<li>\u8bbf\u95ee\u6a21\u5f0f\uff1a\n<ul>\n<li><code>ReadWriteOnce\uff08RWO\uff09<\/code>\uff1a\u53ea\u80fd\u88ab\u5355\u4e2a\u8282\u70b9\u4ee5\u8bfb\u5199\u65b9\u5f0f\u6302\u8f7d\u3002<\/li>\n\n\n\n<li><code>ReadOnlyMany\uff08ROX\uff09<\/code>\uff1a\u53ef\u88ab\u591a\u4e2a\u8282\u70b9\u4ee5\u53ea\u8bfb\u65b9\u5f0f\u6302\u8f7d\u3002<\/li>\n\n\n\n<li><code>ReadWriteMany\uff08RWX\uff09<\/code>\uff1a\u53ef\u88ab\u591a\u4e2a\u8282\u70b9\u4ee5\u8bfb\u5199\u65b9\u5f0f\u6302\u8f7d\uff08\u9700\u5b58\u50a8\u540e\u7aef\u652f\u6301\uff0c\u5982 NFS \uff09\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5b58\u50a8\u7c7b\u522b\uff08StorageClass\uff09\uff1a\u5173\u8054\u5b58\u50a8\u7c7b\uff0c\u7528\u4e8e\u52a8\u6001\u521b\u5efa PV \u65f6\u9009\u62e9\u5b58\u50a8\u540e\u7aef\u3002<\/li>\n\n\n\n<li>\u56de\u6536\u7b56\u7565\uff1aPV \u91ca\u653e\u540e\u5982\u4f55\u5904\u7406\uff08\u5982&nbsp;<code>Retain<\/code>&nbsp;\u4fdd\u7559\u6570\u636e\u3001<code>Delete<\/code>&nbsp;\u5220\u9664\u6570\u636e\u3001<code>Recycle<\/code>&nbsp;\u6e05\u7406\u6570\u636e \uff09\u3002<\/li>\n<\/ul>\n<\/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 apply -f persistent-volume.yaml # \u65e0\u9700\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n  name: wechat-pv\nspec:\n  capacity:\n    storage: 1Gi\n  volumeMode: Filesystem\n  accessModes:\n    - ReadWriteMany  # \u591a\u8282\u70b9\u8bfb\u5199\n  persistentVolumeReclaimPolicy: Retain\n  storageClassName: manual\n  hostPath:\n    path: \"\/Users\/xxx\/Documents\/k8s\/pv\/wechat\"  # \u5bbf\u4e3b\u673a\u8def\u5f84\n    type: DirectoryOrCreate      # \u82e5\u76ee\u5f55\u4e0d\u5b58\u5728\u5219\u521b\u5efa<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"424\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-1024x424.png\" alt=\"\" class=\"wp-image-18175\" style=\"width:568px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-1024x424.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-300x124.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-768x318.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-1536x636.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-2048x849.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-830x344.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-230x95.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-350x145.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-453-480x199.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u5728\u8fd9\u4e2a PersistentVolume (PV) \u914d\u7f6e\u4e2d\uff0c<code>hostPath.path<\/code>&nbsp;\u5b57\u6bb5\u5b9a\u4e49\u7684\u662f&nbsp;<strong>\u5bbf\u4e3b\u673a\uff08Kubernetes \u8282\u70b9\uff09\u4e0a\u7684\u7269\u7406\u8def\u5f84<\/strong>\uff0c\u5373 PV \u5b9e\u9645\u5b58\u50a8\u6570\u636e\u7684\u4f4d\u7f6e\u3002\u5177\u4f53\u6765\u8bf4\uff1a<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><code>path: \"\/Users\/xxx\/Documents\/k8s\/pv\/wechat\"<\/code>&nbsp;\u7684\u542b\u4e49<\/p>\n\n\n\n<ul>\n<li>\u5bbf\u4e3b\u673a\u8def\u5f84\uff1a\u8be5\u8def\u5f84\u6307\u5411 Kubernetes \u8282\u70b9\uff08\u8fd0\u884c Pod \u7684\u7269\u7406\u673a\u6216\u865a\u62df\u673a\uff09\u4e0a\u7684\u4e00\u4e2a\u76ee\u5f55\u3002\u5f53 Pod \u901a\u8fc7 PVC \u6302\u8f7d\u8fd9\u4e2a PV \u65f6\uff0c\u5bb9\u5668\u5185\u7684\u6570\u636e\u4f1a\u88ab\u5b9e\u9645\u5b58\u50a8\u5230\u5bbf\u4e3b\u673a\u7684&nbsp;<code>\/data\/volumes\/my-pv<\/code>&nbsp;\u76ee\u5f55\u4e2d\u3002<\/li>\n\n\n\n<li>\u6570\u636e\u6301\u4e45\u5316\uff1a\u5373\u4f7f Pod \u88ab\u5220\u9664\u6216\u8fc1\u79fb\u5230\u5176\u4ed6\u8282\u70b9\uff0c\u53ea\u8981\u65b0\u8282\u70b9\u4e0a\u5b58\u5728\u76f8\u540c\u7684&nbsp;<code>hostPath<\/code>&nbsp;\u8def\u5f84\uff0c\u6570\u636e\u5c31\u53ef\u4ee5\u88ab\u91cd\u65b0\u6302\u8f7d\uff0c\u4ece\u800c\u5b9e\u73b0\u6301\u4e45\u5316\u5b58\u50a8\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u5728 PersistentVolume\uff08PV\uff09\u4e2d\u4f7f\u7528&nbsp;<code>hostPath<\/code>&nbsp;\u7c7b\u578b\u65f6\uff0c<code>path<\/code>&nbsp;\u5b57\u6bb5\u662f<strong>\u5fc5\u987b\u6307\u5b9a<\/strong>\u7684\uff0c\u5b83\u7528\u4e8e\u660e\u786e\u5bbf\u4e3b\u673a\u4e0a\u5b58\u50a8\u6570\u636e\u7684\u5177\u4f53\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<ul>\n<li>\u6838\u5fc3\u529f\u80fd\u9700\u6c42\uff1a<code>hostPath<\/code>&nbsp;\u7684\u672c\u8d28\u662f\u5c06\u5bbf\u4e3b\u673a\u7684\u672c\u5730\u8def\u5f84\u6620\u5c04\u5230 PV\uff0c\u56e0\u6b64\u5fc5\u987b\u660e\u786e\u6307\u5b9a\u5bbf\u4e3b\u673a\u4e0a\u7684\u76ee\u6807\u8def\u5f84\uff0c\u5426\u5219 PV \u65e0\u6cd5\u786e\u5b9a\u6570\u636e\u5b58\u50a8\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li>\u914d\u7f6e\u5408\u6cd5\u6027\uff1aKubernetes \u4f1a\u6821\u9a8c PV \u914d\u7f6e\u7684\u5b8c\u6574\u6027\uff0c\u7f3a\u5c11&nbsp;<code>path<\/code>&nbsp;\u4f1a\u5bfc\u81f4\u914d\u7f6e\u65e0\u6548\uff0c\u65e0\u6cd5\u521b\u5efa PV\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u5728\u4f7f\u7528&nbsp;<code>kubectl apply -f pv.yaml<\/code>&nbsp;\u65f6\uff0c<strong>\u4e0d\u9700\u8981\u6307\u5b9a&nbsp;<code>namespace<\/code><\/strong>\uff0c\u56e0\u4e3a&nbsp;<strong>PersistentVolume (PV) \u662f\u96c6\u7fa4\u7ea7\u8d44\u6e90<\/strong>\uff0c\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u547d\u540d\u7a7a\u95f4\u3002\u800c&nbsp;<strong>PersistentVolumeClaim (PVC) \u662f\u547d\u540d\u7a7a\u95f4\u7ea7\u8d44\u6e90<\/strong>\uff0c\u9700\u8981\u5728\u7279\u5b9a\u547d\u540d\u7a7a\u95f4\u4e2d\u521b\u5efa\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><strong>\u8d44\u6e90\u7c7b\u578b<\/strong><\/th><th><strong>\u662f\u5426\u9700\u8981\u6307\u5b9a\u547d\u540d\u7a7a\u95f4<\/strong><\/th><th><strong>\u539f\u56e0<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>PersistentVolume<\/strong><\/td><td>\u274c \u4e0d\u9700\u8981<\/td><td>\u96c6\u7fa4\u7ea7\u8d44\u6e90\uff0c\u5168\u5c40\u53ef\u89c1\uff0c\u4e0d\u96b6\u5c5e\u4e8e\u4efb\u4f55\u547d\u540d\u7a7a\u95f4\u3002<\/td><\/tr><tr><td><strong>PersistentVolumeClaim<\/strong><\/td><td>\u2705 \u9700\u8981<\/td><td>\u547d\u540d\u7a7a\u95f4\u7ea7\u8d44\u6e90\uff0c\u5fc5\u987b\u5728\u67d0\u4e2a\u547d\u540d\u7a7a\u95f4\u4e2d\u521b\u5efa\uff0c\u9ed8\u8ba4\u5728&nbsp;<code>default<\/code>&nbsp;\u547d\u540d\u7a7a\u95f4\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p>PV \u4e0e PVC \u7684\u7ed1\u5b9a\uff1aPVC \u53ea\u80fd\u7ed1\u5b9a\u5230<strong>\u8bbf\u95ee\u6a21\u5f0f\u548c\u5b58\u50a8\u7c7b\u5339\u914d<\/strong>\u7684 PV\uff0c\u4e14 PV \u7684\u5bb9\u91cf\u5fc5\u987b \u2265 PVC \u8bf7\u6c42\u7684\u5bb9\u91cf\u3002\u547d\u540d\u7a7a\u95f4\u4e0d\u5f71\u54cd\u7ed1\u5b9a\u903b\u8f91\uff0c\u4f46 PVC \u53ea\u80fd\u5728\u5176\u6240\u5728\u547d\u540d\u7a7a\u95f4\u5185\u88ab Pod \u5f15\u7528\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=\"\"># \u67e5\u770b\u6240\u6709 PV\uff08\u65e0\u547d\u540d\u7a7a\u95f4\u9650\u5236\uff09\nkubectl get pv\n\n# \u67e5\u770b\u7279\u5b9a\u547d\u540d\u7a7a\u95f4\u7684 PVC\nkubectl get pvc -n my-namespace<\/pre>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>3. kubectl<\/strong> <strong>\u521b\u5efaPVC<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u5b9a\u4e49<\/strong>\uff1aPVC \u662f\u7528\u6237\u5bf9\u5b58\u50a8\u8d44\u6e90\u7684 \u201c\u8bf7\u6c42\u58f0\u660e\u201d\uff0c\u7c7b\u4f3c Pod \u5bf9 CPU\u3001\u5185\u5b58\u7684\u8d44\u6e90\u8bf7\u6c42\uff0c<strong>\u63cf\u8ff0 Pod \u5bf9\u5b58\u50a8\u7684\u9700\u6c42<\/strong>\uff08\u8981\u591a\u5927\u3001\u4ee5\u4ec0\u4e48\u65b9\u5f0f\u8bbf\u95ee \uff09\u3002<\/p>\n\n\n\n<p>\u7c7b\u6bd4\uff1aPVC \u662f \u201c\u5b58\u50a8\u7533\u8bf7\u5355\u201d\uff0c\u7528\u6237\u586b \u201c\u8981 5Gi \u5b58\u50a8\u3001\u8bfb\u5199\u6a21\u5f0f\u201d\uff0cK8S \u81ea\u52a8\u5339\u914d PV \u6ee1\u8db3\u9700\u6c42\u3002<\/p>\n\n\n\n<ul>\n<li>\u4f5c\u7528\uff1a\n<ul>\n<li>\u89e3\u8026 Pod \u4e0e\u5177\u4f53\u5b58\u50a8\u5b9e\u73b0\uff08Pod \u53ea\u9700\u58f0\u660e PVC\uff0c\u4e0d\u7528\u5173\u5fc3\u5e95\u5c42\u662f NFS \u8fd8\u662f\u4e91\u5b58\u50a8 \uff09\u3002<\/li>\n\n\n\n<li>\u8ba9\u5b58\u50a8\u8d44\u6e90 \u201c\u6309\u9700\u5206\u914d\u201d\uff0c\u7528\u6237\u65e0\u9700\u63d0\u524d\u4e86\u89e3 PV \u7ec6\u8282\uff0c\u53ea\u9700\u63d0\u9700\u6c42\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5173\u952e\u5c5e\u6027\uff1a\n<ul>\n<li>\u5b58\u50a8\u5bb9\u91cf\uff1a\u5982&nbsp;<code>5Gi<\/code>\uff0c\u8bf7\u6c42\u9700\u8981\u7684\u5b58\u50a8\u5927\u5c0f\u3002<\/li>\n\n\n\n<li>\u8bbf\u95ee\u6a21\u5f0f\uff1a\u4e0e PV \u5339\u914d\uff08\u5982&nbsp;<code>ReadWriteOnce<\/code>&nbsp;\uff09\u3002<\/li>\n\n\n\n<li>\u5b58\u50a8\u7c7b\u522b\uff1a\u6307\u5b9a\u9700\u8981\u7684\u5b58\u50a8\u7c7b\uff0c\u7528\u4e8e\u52a8\u6001\u521b\u5efa PV\uff08\u82e5\u9759\u6001 PV \u4e0d\u8db3\u65f6 \uff09\u3002<\/li>\n\n\n\n<li>\u6807\u7b7e\u9009\u62e9\u5668\uff1a\u901a\u8fc7\u6807\u7b7e\u5339\u914d\u7279\u5b9a PV\uff08\u7cbe\u7ec6\u63a7\u5236 PV \u7ed1\u5b9a \uff09\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u603b\u7ed3\n<ul>\n<li>PV&nbsp;\u662f\u96c6\u7fa4\u91cc\u7684 \u201c\u5b58\u50a8\u8d44\u6e90\u6c60\u201d\uff0c\u7531\u7ba1\u7406\u5458\u7ef4\u62a4\uff0c\u62bd\u8c61\u5e95\u5c42\u5b58\u50a8\uff1b<\/li>\n\n\n\n<li>PVC&nbsp;\u662f\u7528\u6237\u7684 \u201c\u5b58\u50a8\u7533\u8bf7\u5355\u201d\uff0c\u63cf\u8ff0 Pod \u5bf9\u5b58\u50a8\u7684\u9700\u6c42\uff0c\u81ea\u52a8\u5339\u914d PV\uff1b<\/li>\n\n\n\n<li>\u4e8c\u8005\u914d\u5408\u5b9e\u73b0\u4e86&nbsp;<strong>\u5b58\u50a8\u8d44\u6e90\u7684\u89e3\u8026\u3001\u6309\u9700\u5206\u914d\u548c\u52a8\u6001\u7ba1\u7406<\/strong>\uff0c\u8ba9 K8S \u91cc\u7684\u6301\u4e45\u5316\u5b58\u50a8\u66f4\u7075\u6d3b\u3001\u66f4\u6613\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/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 apply -f persistent-volume-claim.yaml -n wechat-applet-services \napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  name: wechat-pvc\nspec:\n  accessModes:\n    - ReadWriteMany\n  resources:\n    requests:\n      storage: 1Gi  # \u8bf7\u6c42\u7684\u5b58\u50a8\u5927\u5c0f\uff08\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e PV \u7684\u5bb9\u91cf\uff09\n  storageClassName: manual  # \u5fc5\u987b\u4e0e PV \u7684 storageClassName \u5339\u914d<\/pre>\n\n\n\n<p>\u3000<\/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=\"429\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-1024x429.png\" alt=\"\" class=\"wp-image-18177\" style=\"width:642px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-1024x429.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-300x126.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-768x322.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-1536x643.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-2048x858.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-830x348.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-230x96.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-350x147.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-455-480x201.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p><code>ReadWriteOnce<\/code>&nbsp;\u662f Kubernetes \u4e2d&nbsp;<strong>PersistentVolume (PV)<\/strong>&nbsp;\u548c&nbsp;<strong>PersistentVolumeClaim (PVC)<\/strong>&nbsp;\u7684\u4e00\u79cd&nbsp;<strong>\u8bbf\u95ee\u6a21\u5f0f\uff08Access Mode\uff09<\/strong>\uff0c\u7528\u4e8e\u5b9a\u4e49\u5b58\u50a8\u5377\u7684\u4f7f\u7528\u9650\u5236\u3002\u5177\u4f53\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><code>ReadWriteOnce<\/code>&nbsp;\u7684\u6838\u5fc3\u5b9a\u4e49<\/p>\n\n\n\n<ul>\n<li>\u5355\u8282\u70b9\u8bfb\u5199\uff1a\u8be5\u5377\u53ef\u4ee5\u88ab<strong>\u5355\u4e2a\u8282\u70b9<\/strong>\u4ee5<strong>\u8bfb\u5199<\/strong>\u65b9\u5f0f\u6302\u8f7d\u3002<\/li>\n\n\n\n<li>\u72ec\u5360\u6027\uff1a\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u4e2a\u8282\u70b9\uff08Node\uff09\u6302\u8f7d\u5e76\u8bfb\u5199\u8be5\u5377\uff0c\u5176\u4ed6\u8282\u70b9\u65e0\u6cd5\u540c\u65f6\u8bbf\u95ee\u3002<\/li>\n\n\n\n<li>Pod \u8fc1\u79fb\u9650\u5236\uff1a\u82e5 Pod \u4ece\u4e00\u4e2a\u8282\u70b9\u8fc1\u79fb\u5230\u53e6\u4e00\u4e2a\u8282\u70b9\uff0c\u5377\u4f1a\u8ddf\u968f\u8fc1\u79fb\uff0c\u4f46\u539f\u8282\u70b9\u5c06\u5931\u53bb\u8bbf\u95ee\u6743\u9650\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>Kubernetes \u652f\u6301\u4e09\u79cd\u4e3b\u8981\u8bbf\u95ee\u6a21\u5f0f\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th><strong>\u8bbf\u95ee\u6a21\u5f0f<\/strong><\/th><th><strong>\u7f29\u5199<\/strong><\/th><th><strong>\u542b\u4e49<\/strong><\/th><\/tr><\/thead><tbody><tr><td><code>ReadWriteOnce<\/code><\/td><td><code>RWO<\/code><\/td><td>\u5355\u8282\u70b9\u8bfb\u5199\uff08\u6700\u5e38\u7528\uff0c\u9002\u7528\u4e8e\u591a\u6570\u6570\u636e\u5e93\u7b49\u9700\u8981\u72ec\u5360\u8bbf\u95ee\u7684\u573a\u666f\uff09\u3002<\/td><\/tr><tr><td><code>ReadOnlyMany<\/code><\/td><td><code>ROX<\/code><\/td><td>\u591a\u8282\u70b9\u53ea\u8bfb\uff08\u9002\u7528\u4e8e\u9759\u6001\u8d44\u6e90\u5171\u4eab\uff0c\u5982\u7f51\u7ad9\u9759\u6001\u6587\u4ef6\uff09\u3002<\/td><\/tr><tr><td><code>ReadWriteMany<\/code><\/td><td><code>RWX<\/code><\/td><td>\u591a\u8282\u70b9\u8bfb\u5199\uff08\u9700\u5b58\u50a8\u7cfb\u7edf\u652f\u6301\uff0c\u5982 NFS\u3001Ceph \u7b49\u5206\u5e03\u5f0f\u5b58\u50a8\uff09\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><code>ReadWriteOnce<\/code>&nbsp;\u7684\u5178\u578b\u573a\u666f<\/p>\n\n\n\n<ol>\n<li>\u6570\u636e\u5e93\u5b58\u50a8\uff1a\n<ul>\n<li>\u5982 MySQL\u3001PostgreSQL \u7b49\u6570\u636e\u5e93\u9700\u8981\u72ec\u5360\u5b58\u50a8\uff0c\u907f\u514d\u591a\u8282\u70b9\u540c\u65f6\u5199\u5165\u5bfc\u81f4\u6570\u636e\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<ol>\n<li>\u672c\u5730\u5b58\u50a8\u4f9d\u8d56\uff1a\n<ul>\n<li>\u67d0\u4e9b\u5e94\u7528\u4f9d\u8d56\u7279\u5b9a\u8282\u70b9\u7684\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\uff08\u5982&nbsp;<code>hostPath<\/code>&nbsp;\u7c7b\u578b\u7684 PV\uff09\uff0c\u5fc5\u987b\u9650\u5236\u5728\u5355\u8282\u70b9\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u4e91\u5b58\u50a8\u5377\uff1a\n<ul>\n<li>AWS EBS\u3001GCE PD \u7b49\u4e91\u5b58\u50a8\u5377\u672c\u8eab\u9650\u5236\u53ea\u80fd\u6302\u8f7d\u5230\u5355\u4e2a\u5b9e\u4f8b\uff0c\u5bf9\u5e94&nbsp;<code>ReadWriteOnce<\/code>&nbsp;\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\uff14. kubectl<\/strong> <strong>\u521b\u5efaDeployment<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\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-wechat-deployment.yaml\n# kubectl apply -f service-wechat-deployment.yaml -n wechat-applet-services\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: service-wechat-deployment\n  labels:\n    app: service-wechat\nspec:\n  replicas: 1  # \u521b\u5efa1\u4e2aPod\u526f\u672c\n  selector:\n    matchLabels:\n      app: service-wechat\n  template:\n    metadata:\n      labels:\n        app: service-wechat\n    spec:\n      containers:\n      - name: service-wechat\n        image: 123.57.xxx.xxx:5001\/service-wechat:latest\n        ports:\n        - containerPort: 8081\n        resources:\n          limits:\n            memory: \"512Mi\"\n            cpu: \"500m\"\n        volumeMounts:\n        - name: service-wechat-volume\n          mountPath: \"\/mnt\"  # \u5bb9\u5668\u5185\u6302\u8f7d\u8def\u5f84\uff0c\u4f1a\u628apvc\u6302\u5230\u5bb9\u5668 \/mnt\u76ee\u5f55\u4e0b\n      imagePullSecrets:\n      - name: docker-registry-secret\n      volumes:\n      - name: service-wechat-volume\n        persistentVolumeClaim:\n          claimName: wechat-pvc # \u7528\u5230\u4e86\u4e0a\u9762\u7684pvc<\/pre>\n\n\n\n<p>\u3000\u3000\u5728\u5bbf\u4e3b\u673a\u4e0a\u53ef\u4ee5\u770b\u5230 Pod\u7528\u5230\u4e86\u4e0a\u9762\u7ed1\u5b9a\u7684pv\u548cpvc\uff0c\u8fd9\u4e2a\u8def\u5f84\u4e0b\u9762\u6709\u4e86pod\u4ea7\u751f\u7684\u6587\u4ef6\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"672\" height=\"308\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-458.png\" alt=\"\" class=\"wp-image-18183\" style=\"width:420px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-458.png 672w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-458-300x138.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-458-230x105.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-458-350x160.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-458-480x220.png 480w\" sizes=\"(max-width: 672px) 100vw, 672px\" \/><\/figure><\/div>\n\n\n<p>\u8fdb\u5230k8s\u5bb9\u5668\u91cc\u9762\u770b\u4e00\u4e0b<\/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=\"319\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-1024x319.png\" alt=\"\" class=\"wp-image-18185\" style=\"width:568px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-1024x319.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-300x93.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-768x239.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-1536x478.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-830x258.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-230x72.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-350x109.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460-480x149.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-460.png 1652w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>5. kubectl<\/strong> <strong>\u521b\u5efaService \u901a\u8fc7 nodePort<\/strong> <strong>\u66b4\u9732\u670d\u52a1<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\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=\"\"># wechat-service.yaml\n# kubectl apply -f wechat-service.yaml -n wechat-applet-services\napiVersion: v1\nkind: Service\nmetadata:\n  name: wechat-service\nspec:\n  selector:\n    app: service-wechat\n  ports:\n    - protocol: TCP\n      port: 80\n      targetPort: 8081\n      nodePort: 30080  # \u6307\u5b9a NodePort\uff08\u8303\u56f4 30000-32767\uff09\n  type: NodePort  # \u66b4\u9732\u5230\u96c6\u7fa4\u5916<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"343\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-1024x343.png\" alt=\"\" class=\"wp-image-18179\" style=\"width:674px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-1024x343.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-300x101.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-768x257.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-1536x515.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-2048x687.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-830x278.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-230x77.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-350x117.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-457-480x161.png 480w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u5728 Kubernetes \u7684 Service \u914d\u7f6e\u4e2d\uff0c<code>port<\/code>\u3001<code>targetPort<\/code>&nbsp;\u548c&nbsp;<code>nodePort<\/code>&nbsp;\u662f\u4e09\u4e2a\u5173\u952e\u6982\u5ff5\uff0c\u5b83\u4eec\u5206\u522b\u5bf9\u5e94\u4e0d\u540c\u5c42\u7ea7\u7684\u7aef\u53e3\u6620\u5c04\u5173\u7cfb\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u89e3\u91ca\uff1a<\/p>\n\n\n\n<p><strong style=\"-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); font-weight: 600; color: rgb(0, 0, 0) !important; font-size: 16px; line-height: 28px; overflow-anchor: auto;\">port\uff1aService \u81ea\u8eab\u7684\u7aef\u53e3\uff08\u96c6\u7fa4\u5185\u90e8\u8bbf\u95ee\uff09<\/strong><\/p>\n\n\n\n<ul>\n<li><strong style=\"-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); font-weight: 600; color: rgb(0, 0, 0) !important; font-size: 16px; line-height: 28px; overflow-anchor: auto;\">\u5b9a\u4e49<\/strong>\uff1aService \u5728\u96c6\u7fa4\u5185\u90e8 IP \u4e0a\u66b4\u9732\u7684\u7aef\u53e3\uff0c\u7528\u4e8e\u96c6\u7fa4\u5185\u5176\u4ed6 Pod \u6216\u670d\u52a1\u901a\u8fc7\u8be5\u7aef\u53e3\u8bbf\u95ee\u6b64 Service\u3002<\/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=\"\">ports:\n  - protocol: TCP\n    port: 80  # Service \u5728\u96c6\u7fa4\u5185\u90e8\u7684\u7aef\u53e3\u4e3a 80<\/pre>\n\n\n\n<ul>\n<li><strong>\u4f5c\u7528<\/strong>\uff1a\u5f53\u96c6\u7fa4\u5185\u7684 Pod \u8bbf\u95ee&nbsp;<code>wechat-service:80<\/code>&nbsp;\u65f6\uff0c\u6d41\u91cf\u4f1a\u88ab Service \u8f6c\u53d1\u5230\u540e\u7aef Pod \u7684&nbsp;<code>targetPort<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>targetPort\uff1a\u540e\u7aef Pod \u7684\u76ee\u6807\u7aef\u53e3<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>\uff1aService \u8f6c\u53d1\u6d41\u91cf\u65f6\u6307\u5411\u7684\u540e\u7aef Pod \u7684\u7aef\u53e3\uff0c\u9700\u4e0e Pod \u4e2d\u5bb9\u5668\u7684\u7aef\u53e3\u4e00\u81f4\u3002<\/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=\"\">ports:\n  - targetPort: 8081  # \u8f6c\u53d1\u5230 Pod \u4e2d\u5bb9\u5668\u7684 8081 \u7aef\u53e3<\/pre>\n\n\n\n<ul>\n<li><strong>\u4f5c\u7528<\/strong>\uff1a\u5047\u8bbe Pod \u4e2d\u5bb9\u5668\u7684\u7aef\u53e3\u4e3a 8081\uff08\u5982&nbsp;<code>containerPort: 8081<\/code>\uff09\uff0c\u5219 Service \u4f1a\u5c06\u8bf7\u6c42\u4ece&nbsp;<code>port<\/code>&nbsp;\u8f6c\u53d1\u5230 Pod \u7684&nbsp;<code>targetPort<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>nodePort\uff1a\u8282\u70b9\u66b4\u9732\u7684\u7aef\u53e3\uff08\u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee\uff09<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u5f53&nbsp;<code>type: NodePort<\/code>&nbsp;\u65f6\uff0cKubernetes \u4f1a\u5728\u96c6\u7fa4\u6240\u6709\u8282\u70b9\u4e0a\u5f00\u653e\u4e00\u4e2a\u7aef\u53e3\uff08<code>nodePort<\/code>\uff09\uff0c\u5916\u90e8\u6d41\u91cf\u53ef\u901a\u8fc7\u8282\u70b9 IP +&nbsp;<code>nodePort<\/code>&nbsp;\u8bbf\u95ee\u670d\u52a1\u3002<\/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=\"\">ports:\n  - nodePort: 30080  # \u8282\u70b9\u4e0a\u5f00\u653e\u7684\u7aef\u53e3\u4e3a 30080\ntype: NodePort<\/pre>\n\n\n\n<ul>\n<li><strong>\u4f5c\u7528<\/strong>\uff1a\u5916\u90e8\u7528\u6237\u53ef\u901a\u8fc7&nbsp;<code>http:\/\/&lt;\u8282\u70b9IP&gt;:30080<\/code>&nbsp;\u8bbf\u95ee\u670d\u52a1\uff0c\u6d41\u91cf\u4f1a\u88ab\u8282\u70b9\u8f6c\u53d1\u5230 Service \u7684&nbsp;<code>port<\/code>\uff0c\u518d\u7531 Service \u8f6c\u53d1\u5230 Pod \u7684&nbsp;<code>targetPort<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u7aef\u53e3\u8303\u56f4<\/strong>\uff1a<code>nodePort<\/code>&nbsp;\u5fc5\u987b\u5728&nbsp;<code>30000-32767<\/code>&nbsp;\u8303\u56f4\u5185\uff0c\u82e5\u4e0d\u6307\u5b9a\uff0cKubernetes \u4f1a\u81ea\u52a8\u5206\u914d\u4e00\u4e2a\u53ef\u7528\u7aef\u53e3\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e09\u8005\u7684\u6620\u5c04\u5173\u7cfb\uff08\u4ee5\u793a\u4f8b\u914d\u7f6e\u4e3a\u4f8b\uff09<\/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=\"\">\u5916\u90e8\u8bbf\u95ee \u2192 \u8282\u70b9 IP:30080\uff08nodePort\uff09\n       \u2193\nService \u5185\u90e8 IP:80\uff08port\uff09\n       \u2193\n\u540e\u7aef Pod:8081\uff08targetPort\uff09<\/pre>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u7aef\u53e3\u7c7b\u578b<\/th><th>\u4f5c\u7528\u8303\u56f4<\/th><th>\u793a\u4f8b\u503c<\/th><th>\u8bbf\u95ee\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td><code>port<\/code><\/td><td>\u96c6\u7fa4\u5185\u90e8<\/td><td>80<\/td><td>\u96c6\u7fa4\u5185 Pod \u901a\u8fc7&nbsp;<code>\u670d\u52a1\u540d:port<\/code>&nbsp;\u8bbf\u95ee<\/td><\/tr><tr><td><code>targetPort<\/code><\/td><td>\u540e\u7aef Pod<\/td><td>8081<\/td><td>Service \u8f6c\u53d1\u5230 Pod \u7684\u76ee\u6807\u7aef\u53e3<\/td><\/tr><tr><td><code>nodePort<\/code><\/td><td>\u96c6\u7fa4\u6240\u6709\u8282\u70b9<\/td><td>30080<\/td><td>\u5916\u90e8\u901a\u8fc7&nbsp;<code>\u8282\u70b9IP:nodePort<\/code>&nbsp;\u8bbf\u95ee<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u6269\u5c55\u8bf4\u660e<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u4e3a\u4ec0\u4e48\u9700\u8981\u4e09\u5c42\u7aef\u53e3\uff1f<\/strong>\n<ul>\n<li><code>port<\/code>&nbsp;\u548c&nbsp;<code>targetPort<\/code>&nbsp;\u89e3\u8026\u4e86 Service \u4e0e Pod \u7684\u7aef\u53e3\u4f9d\u8d56\uff08\u5982 Pod \u7aef\u53e3\u53d8\u66f4\u65f6\uff0c\u53ea\u9700\u4fee\u6539&nbsp;<code>targetPort<\/code>\uff09\u3002<\/li>\n\n\n\n<li><code>nodePort<\/code>&nbsp;\u63d0\u4f9b\u4e86\u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee\u7684\u7edf\u4e00\u5165\u53e3\uff0c\u907f\u514d\u76f4\u63a5\u66b4\u9732 Pod \u5730\u5740\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4e0e Ingress \u7684\u533a\u522b<\/strong><br>NodePort \u9002\u5408\u7b80\u5355\u573a\u666f\uff0c\u4f46\u5b58\u5728\u4ee5\u4e0b\u9650\u5236\uff1a\n<ul>\n<li>\u6bcf\u4e2a Service \u5360\u7528\u4e00\u4e2a\u8282\u70b9\u7aef\u53e3\uff0c\u7aef\u53e3\u8d44\u6e90\u6709\u9650\u3002<\/li>\n\n\n\n<li>\u65e0\u6cd5\u57fa\u4e8e\u57df\u540d\u3001\u8def\u5f84\u8fdb\u884c\u8def\u7531\uff08\u9700 Ingress \u5b9e\u73b0\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e2a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u540e\u7aef\u670d\u52a1\uff0c\u539f\u6765\u6258\u7ba1\u5728\u963f\u91cc\u4e91\u4e0a\uff0c\u73b0\u5728\u5e0c\u671b\u505a\u6210\u5fae\u670d\u52a1\u53d1\u5e03\u5728k8s\u4e0a\u3002 1.\u914d\u7f6e nginx \u5bb9\u5668\uff0c [&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\/18169"}],"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=18169"}],"version-history":[{"count":11,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18169\/revisions"}],"predecessor-version":[{"id":19391,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18169\/revisions\/19391"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}