{"id":18448,"date":"2025-07-15T22:17:45","date_gmt":"2025-07-15T14:17:45","guid":{"rendered":"https:\/\/92it.top\/?p=18448"},"modified":"2025-07-15T22:17:45","modified_gmt":"2025-07-15T14:17:45","slug":"k8s-yaml-%e7%9a%84-metadata-%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=18448","title":{"rendered":"k8s Yaml \u7684 metadata \u662f\u4ec0\u4e48"},"content":{"rendered":"\n<p>\u5728 Kubernetes\uff08k8s\uff09\u4e2d\uff0c<code>metadata<\/code>\u662f\u8d44\u6e90\u5bf9\u8c61\uff08\u5982 Pod\u3001Deployment\u3001Service \u7b49\uff09\u7684\u6838\u5fc3\u7ec4\u6210\u90e8\u5206\uff0c\u7528\u4e8e<strong>\u552f\u4e00\u6807\u8bc6\u8d44\u6e90<\/strong>\u5e76<strong>\u9644\u52a0\u63cf\u8ff0\u6027\u4fe1\u606f<\/strong>\u3002\u5b83\u7c7b\u4f3c\u4e8e\u8d44\u6e90\u7684 \u201c\u540d\u7247\u201d\uff0c\u5305\u542b\u4e86\u8d44\u6e90\u7684\u540d\u79f0\u3001\u547d\u540d\u7a7a\u95f4\u3001\u6807\u7b7e\u3001\u6ce8\u91ca\u7b49\u5173\u952e\u5c5e\u6027\u3002<\/p>\n\n\n\n<p><strong>\u4e00\u3001<code>metadata<\/code>\u7684\u6838\u5fc3\u4f5c\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ol>\n<li><strong>\u552f\u4e00\u6807\u8bc6\u8d44\u6e90<\/strong><br>\u901a\u8fc7<code>name<\/code>\u548c<code>namespace<\/code>\u786e\u4fdd\u8d44\u6e90\u5728\u96c6\u7fa4\u4e2d\u7684\u552f\u4e00\u6027\u3002<\/li>\n\n\n\n<li><strong>\u5206\u7c7b\u548c\u7b5b\u9009<\/strong><br>\u4f7f\u7528<code>labels<\/code>\u5bf9\u8d44\u6e90\u8fdb\u884c\u5206\u7ec4\uff08\u5982\u6309\u73af\u5883\u3001\u529f\u80fd\u3001\u56e2\u961f\u5206\u7c7b\uff09\u3002<\/li>\n\n\n\n<li><strong>\u9644\u52a0\u63cf\u8ff0\u4fe1\u606f<\/strong><br>\u901a\u8fc7<code>annotations<\/code>\u5b58\u50a8\u975e\u6807\u8bc6\u6027\u5143\u6570\u636e\uff08\u5982\u6784\u5efa\u4fe1\u606f\u3001\u8fd0\u7ef4\u6307\u5357\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7248\u672c\u63a7\u5236<\/strong><br><code>resourceVersion<\/code>\u548c<code>uid<\/code>\u7528\u4e8e\u8ddf\u8e2a\u8d44\u6e90\u53d8\u66f4\u548c\u552f\u4e00\u6807\u8bc6\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e8c\u3001<code>metadata<\/code>\u7684\u5e38\u89c1\u5b57\u6bb5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>1. \u5fc5\u9009\u5b57\u6bb5<\/strong><\/p>\n\n\n\n<ul>\n<li><strong><code>name<\/code><\/strong><br>\u8d44\u6e90\u7684\u540d\u79f0\uff0c\u5fc5\u987b\u5728\u547d\u540d\u7a7a\u95f4\u5185\u552f\u4e00\uff08\u5982<code>nginx-pod<\/code>\uff09\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=\"\">metadata:\n  name: my-pod<\/pre>\n\n\n\n<ul>\n<li><strong><code>namespace<\/code><\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u8d44\u6e90\u6240\u5c5e\u7684\u547d\u540d\u7a7a\u95f4\uff08\u9ed8\u8ba4<code>default<\/code>\uff09\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=\"\">metadata:\n  namespace: production<\/pre>\n\n\n\n<p><strong>2. \u6807\u7b7e\uff08<code>labels<\/code>\uff09<\/strong><\/p>\n\n\n\n<p>\u7528\u4e8e\u5bf9\u8d44\u6e90\u8fdb\u884c\u5206\u7c7b\u7684\u952e\u503c\u5bf9\uff0c\u5e38\u7528\u4e8e\u9009\u62e9\u5668\uff08Selector\uff09\u548c\u76d1\u63a7\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=\"\">metadata:\n  labels:\n    app: nginx\n    env: production\n    tier: frontend<\/pre>\n\n\n\n<p><strong>3. \u6ce8\u91ca\uff08<code>annotations<\/code>\uff09<\/strong><\/p>\n\n\n\n<p>\u5b58\u50a8\u975e\u6807\u8bc6\u6027\u5143\u6570\u636e\uff08\u5982\u6784\u5efa\u7248\u672c\u3001\u6587\u6863\u94fe\u63a5\u3001\u5de5\u5177\u914d\u7f6e\uff09\uff0c\u4e0d\u7528\u4e8e\u7b5b\u9009\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=\"\">metadata:\n  annotations:\n    buildVersion: \"v1.2.3\"\n    documentation: \"https:\/\/example.com\/docs\"\n    kubernetes.io\/change-cause: \"Update to latest version\"<\/pre>\n\n\n\n<p><strong>4. \u5176\u4ed6\u5b57\u6bb5<\/strong><\/p>\n\n\n\n<ul>\n<li><strong><code>uid<\/code><\/strong><br>Kubernetes \u81ea\u52a8\u751f\u6210\u7684\u5168\u5c40\u552f\u4e00\u6807\u8bc6\u7b26\uff08\u5982<code>123e4567-e89b-12d3-a456-426614174000<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong><code>resourceVersion<\/code><\/strong><br>\u8d44\u6e90\u7684\u5185\u90e8\u7248\u672c\u53f7\uff0c\u6bcf\u6b21\u4fee\u6539\u65f6\u9012\u589e\uff08\u7528\u4e8e\u5e76\u53d1\u63a7\u5236\uff09\u3002<\/li>\n\n\n\n<li><strong><code>creationTimestamp<\/code><\/strong><br>\u8d44\u6e90\u521b\u5efa\u7684\u65f6\u95f4\u6233\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u56db\u3001\u5b9e\u6218\u793a\u4f8b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a Pod \u7684<code>metadata<\/code>\u5b8c\u6574\u793a\u4f8b\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=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  name: my-app-pod\n  namespace: production\n  labels:\n    app: my-app\n    env: production\n    tier: backend\n  annotations:\n    buildVersion: \"v2.0.1\"\n    created-by: \"jenkins-pipeline\"\n    documentation: \"https:\/\/internal\/docs\/my-app\"\nspec:\n  containers:\n  - name: app-container\n    image: my-app:v2.0.1<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e94\u3001\u4e3a\u4ec0\u4e48<code>metadata<\/code>\u5982\u6b64\u91cd\u8981\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<ol>\n<li><strong>\u8d44\u6e90\u7ba1\u7406<\/strong><br>\u901a\u8fc7\u6807\u7b7e\u5feb\u901f\u7b5b\u9009\u8d44\u6e90\uff08\u5982<code>kubectl get pods -l env=dev<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u81ea\u52a8\u5316\u90e8\u7f72<\/strong><br>CI\/CD \u5de5\u5177\u901a\u8fc7\u6ce8\u91ca\u6ce8\u5165\u6784\u5efa\u4fe1\u606f\uff08\u5982\u7248\u672c\u53f7\u3001\u63d0\u4ea4\u54c8\u5e0c\uff09\u3002<\/li>\n\n\n\n<li><strong>\u76d1\u63a7\u548c\u544a\u8b66<\/strong><br>\u76d1\u63a7\u7cfb\u7edf\u57fa\u4e8e\u6807\u7b7e\u805a\u5408\u6307\u6807\uff08\u5982\u6309<code>app<\/code>\u548c<code>env<\/code>\u5206\u7ec4\uff09\u3002<\/li>\n\n\n\n<li><strong>\u751f\u547d\u5468\u671f\u7ba1\u7406<\/strong><br><code>uid<\/code>\u548c<code>resourceVersion<\/code>\u786e\u4fdd\u8d44\u6e90\u53d8\u66f4\u7684\u539f\u5b50\u6027\u548c\u552f\u4e00\u6027\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Kubernetes\uff08k8s\uff09\u4e2d\uff0cmetadata\u662f\u8d44\u6e90\u5bf9\u8c61\uff08\u5982 Pod\u3001Deployment\u3001Servi [&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\/18448"}],"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=18448"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18448\/revisions"}],"predecessor-version":[{"id":18449,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/18448\/revisions\/18449"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}