{"id":630,"date":"2023-11-01T17:51:35","date_gmt":"2023-11-01T09:51:35","guid":{"rendered":"http:\/\/madapapa.com\/wordpress\/?p=630"},"modified":"2023-11-01T17:55:56","modified_gmt":"2023-11-01T09:55:56","slug":"k8s-qin-he-du-diao-du","status":"publish","type":"post","link":"http:\/\/madapapa.com\/wordpress\/?p=630","title":{"rendered":"k8s\u4eb2\u548c\u5ea6\u8c03\u5ea6"},"content":{"rendered":"<p><a href=\"https:\/\/developer.aliyun.com\/article\/1335508\">\u963f\u91cc\u4e91\u7684\u8fd9\u7bc7\u6587\u7ae0<\/a>\uff0c\u4ecb\u7ecd\u4e86\u5982\u4f55\u5229\u7528\u4eb2\u548c\u5ea6\uff08or\u53cd\u4eb2\u548c\u5ea6\uff09\u7279\u6027\uff0c\u6765\u5b9e\u73b0pod\u7684\u8c03\u5ea6\u3002<br \/>\n\u8fd9\u91cc\u6709\u4e00\u4e2a\u4f8b\u5b50\uff0c\u7528\u6765\u628apod\u8c03\u5ea6\u5230\u7279\u5b9a\u540d\u5b57\u7684node\u4e0a\u3002<\/p>\n<pre><code class=\"language-plain_text\">\u6bd4\u5982\u8981\u5c06Pod\u8c03\u5ea6\u5230nodeName\u662fk8s-worker-2\u7684\u8282\u70b9\u4e0a\napiVersion: v1\nkind: Pod\nmetadata:\n  name: webapp\n  namespace: demo\n  labels:\n    app: webapp\nspec:\n  nodeName: 'k8s-worker-2'\n  containers:\n    - name: webapp\n      image: nginx\n      ports:\n        - containerPort: 80\n<\/code><\/pre>\n<p>\u4e0b\u9762\u662fchatgpt\u5bf9\u8fd9\u6bb5\u811a\u672c\u7684\u8be6\u7ec6\u89e3\u91ca<\/p>\n<pre><code class=\"language-plain_text\">The YAML configuration you've provided is for a Kubernetes Pod named &quot;webapp&quot; in the &quot;demo&quot; namespace. Here's a breakdown of the configuration:\n\n- `apiVersion: v1` and `kind: Pod`: These fields specify the Kubernetes API version and the resource type, which, in this case, is a Pod.\n\n- `metadata`: This section contains metadata information for the Pod, such as its name, namespace, and labels.\n\n  - `name: webapp`: The name of the Pod is set to &quot;webapp.&quot;\n\n  - `namespace: demo`: The Pod is created within the &quot;demo&quot; namespace.\n\n  - `labels`: Labels are key-value pairs that help you organize and categorize Pods. In this case, the label &quot;app&quot; is set to &quot;webapp.&quot;\n\n- `spec`: This section defines the specifications of the Pod, including its containers, resources, and other settings.\n\n  - `nodeName: 'k8s-worker-2'`: This field specifies the node (Kubernetes worker node) where the Pod should be scheduled. It pins the Pod to a specific node named &quot;k8s-worker-2.&quot; This is known as node affinity and ensures that the Pod runs on a specific node, which can be useful for various scenarios such as hardware requirements or node-specific configurations.\n\n  - `containers`: This is a list of containers running within the Pod. In this case, there is one container defined.\n\n    - `name: webapp`: The container is named &quot;webapp.&quot;\n\n    - `image: nginx`: This field specifies the Docker image to use for this container. In this case, it uses the official Nginx image.\n\n    - `ports`: This field defines the ports that are exposed by the container.\n\n      - `containerPort: 80`: The container exposes port 80, which is the default port for HTTP traffic, allowing the Nginx web server within the container to listen for incoming HTTP requests.\n\nThis configuration will create a Pod running an Nginx web server on a specific node named &quot;k8s-worker-2&quot; in the &quot;demo&quot; namespace. The web server within the Pod will be accessible on port 80, and it has the label &quot;app=webapp&quot; for categorization and selection purposes.\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u963f\u91cc\u4e91\u7684\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4ecb\u7ecd\u4e86\u5982\u4f55\u5229\u7528\u4eb2\u548c\u5ea6\uff08or\u53cd\u4eb2\u548c\u5ea6\uff09\u7279\u6027\uff0c\u6765\u5b9e\u73b0pod\u7684\u8c03\u5ea6\u3002 \u8fd9\u91cc\u6709\u4e00\u4e2a\u4f8b\u5b50\uff0c\u7528\u6765\u628apod\u8c03\u5ea6\u5230\u7279\u5b9a\u540d\u5b57\u7684node\u4e0a\u3002 \u6bd4\u5982\u8981\u5c06Pod\u8c03\u5ea6\u5230nodeName\u662fk8s-worker-2\u7684\u8282\u70b9\u4e0a apiVersion: v1 kind: Pod metadata: name: webapp namespace: demo labels: app: webapp spec: nodeName: &#8216;k8s-worker-2&#8217; containers: &#8211; name: webapp image: nginx ports: &#8211; containerPort: 80 \u4e0b\u9762\u662fchatgpt\u5bf9\u8fd9\u6bb5\u811a\u672c\u7684\u8be6\u7ec6\u89e3\u91ca The YAML configuration you&#8217;ve provided is for a Kubernetes Pod named &quot;webapp&quot; in the &quot;demo&quot; namespace. Here&#8217;s a breakdown of the configuration: &#8211; `apiVersion: v1` and &hellip; <a href=\"http:\/\/madapapa.com\/wordpress\/?p=630\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">k8s\u4eb2\u548c\u5ea6\u8c03\u5ea6<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-630","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=630"}],"version-history":[{"count":1,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":631,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions\/631"}],"wp:attachment":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}