{"id":69370,"date":"2026-01-31T15:40:51","date_gmt":"2026-01-31T07:40:51","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69370.html"},"modified":"2026-01-31T15:40:51","modified_gmt":"2026-01-31T07:40:51","slug":"kubernetes%e5%9f%ba%e7%a1%80%e5%85%a5%e9%97%a83-%e4%bd%bf%e7%94%a8-service-%e5%ae%9e%e7%8e%b0%e5%a4%96%e9%83%a8%e8%ae%bf%e9%97%ae","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69370.html","title":{"rendered":"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee"},"content":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u00a0Service\u00a0\u66b4\u9732\u5e94\u7528\u3001\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0&#xff0c;\u5e76\u7ba1\u7406\u76f8\u5173\u6807\u7b7e\u3002<\/p>\n<h3>&#x1f4cc; \u6838\u5fc3\u6982\u5ff5&#xff1a;Kubernetes Service<\/h3>\n<h4>\u4ec0\u4e48\u662f Service&#xff1f;<\/h4>\n<p>Pod \u662f\u6709\u751f\u547d\u5468\u671f\u7684&#xff0c;\u5f53\u8282\u70b9\u6545\u969c\u6216\u88ab\u66ff\u6362\u65f6&#xff0c;\u5176\u4e0a\u7684 Pod \u4f1a\u968f\u4e4b\u6d88\u4ea1&#xff0c;\u5e76\u7531 ReplicaSet \u7b49\u63a7\u5236\u5668\u521b\u5efa\u65b0 Pod \u6765\u66ff\u6362\u3002\u8fd9\u4e9b\u65b0 Pod \u4f1a\u5206\u914d\u65b0\u7684 IP \u5730\u5740\u3002Service \u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u7531\u6b64\u4ea7\u751f\u7684\u670d\u52a1\u53d1\u73b0\u4e0e\u7a33\u5b9a\u8bbf\u95ee\u7aef\u70b9\u95ee\u9898\u800c\u8bbe\u8ba1\u7684\u62bd\u8c61\u5c42\u3002<\/p>\n<p>Service \u7684\u6838\u5fc3\u4f5c\u7528&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5b9a\u4e49\u4e00\u7ec4 Pod \u7684\u903b\u8f91\u96c6\u5408<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u8fd9\u7ec4 Pod \u63d0\u4f9b\u7edf\u4e00\u7684\u8bbf\u95ee\u5165\u53e3&#xff08;\u7aef\u70b9&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861<\/p>\n<\/li>\n<li>\n<p>\u63d0\u4f9b\u670d\u52a1\u53d1\u73b0\u673a\u5236<\/p>\n<\/li>\n<\/ul>\n<p>\u901a\u8fc7 Service&#xff0c;\u5373\u4f7f\u540e\u7aef Pod \u53d1\u751f\u53d8\u66f4&#xff0c;\u524d\u7aef\u5e94\u7528\u4e5f\u65e0\u9700\u5173\u5fc3\u5177\u4f53\u7684 Pod IP&#xff0c;\u5b9e\u73b0\u4e86\u524d\u540e\u7aef\u4e4b\u95f4\u7684\u677e\u8026\u5408\u3002<\/p>\n<h4>Service \u7684\u7c7b\u578b<\/h4>\n<p>\u5728\u5b9a\u4e49 Service \u65f6&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u00a0spec.type\u00a0\u5b57\u6bb5\u6307\u5b9a\u4e0d\u540c\u7684\u66b4\u9732\u65b9\u5f0f&#xff1a;<\/p>\n<table>\n<tr>\u7c7b\u578b\u8bf4\u660e\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>ClusterIP\u00a0(\u9ed8\u8ba4)<\/td>\n<td>\u5728\u96c6\u7fa4\u5185\u90e8 IP \u4e0a\u66b4\u9732\u670d\u52a1&#xff0c;\u4ec5\u9650\u96c6\u7fa4\u5185\u90e8\u8bbf\u95ee<\/td>\n<td>\u5185\u90e8\u5fae\u670d\u52a1\u95f4\u901a\u4fe1<\/td>\n<\/tr>\n<tr>\n<td>NodePort<\/td>\n<td>\u901a\u8fc7 NAT \u5728\u6bcf\u4e2a\u8282\u70b9\u7684\u76f8\u540c\u7aef\u53e3\u4e0a\u66b4\u9732\u670d\u52a1&#xff0c;\u53ef\u901a\u8fc7\u00a0\u8282\u70b9IP:\u8282\u70b9\u7aef\u53e3\u00a0\u4ece\u5916\u90e8\u8bbf\u95ee<\/td>\n<td>\u5f00\u53d1\u6d4b\u8bd5\u3001\u7b80\u5355\u5916\u90e8\u8bbf\u95ee<\/td>\n<\/tr>\n<tr>\n<td>LoadBalancer<\/td>\n<td>\u5229\u7528\u4e91\u5e73\u53f0\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u5206\u914d\u5916\u90e8 IP&#xff0c;\u81ea\u52a8\u5c06\u6d41\u91cf\u5bfc\u5411 Service<\/td>\n<td>\u751f\u4ea7\u73af\u5883&#xff0c;\u4e91\u5e73\u53f0\u652f\u6301\u65f6<\/td>\n<\/tr>\n<tr>\n<td>ExternalName<\/td>\n<td>\u5c06 Service \u6620\u5c04\u5230\u5916\u90e8\u57df\u540d&#xff08;CNAME \u8bb0\u5f55&#xff09;&#xff0c;\u65e0\u4ee3\u7406<\/td>\n<td>\u96c6\u6210\u5916\u90e8\u670d\u52a1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>NodePort \u662f ClusterIP \u7684\u8d85\u96c6&#xff0c;LoadBalancer \u662f NodePort \u7684\u8d85\u96c6\u3002<\/p>\n<h3>&#x1f3f7;\ufe0f \u670d\u52a1\u4e0e\u6807\u7b7e&#xff08;Labels&#xff09;<\/h3>\n<p>Service \u901a\u8fc7\u00a0\u6807\u7b7e\u9009\u62e9\u5668&#xff08;Label Selector&#xff09;\u00a0\u6765\u5339\u914d\u4e00\u7ec4 Pod\u3002\u6807\u7b7e\u662f\u9644\u52a0\u5230\u5bf9\u8c61&#xff08;\u5982 Pod&#xff09;\u4e0a\u7684\u952e\u503c\u5bf9&#xff0c;\u7528\u4e8e\u903b\u8f91\u5206\u7ec4\u3002<\/p>\n<p>\u6807\u7b7e\u7684\u5e38\u89c1\u7528\u9014&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6807\u8bc6\u73af\u5883&#xff08;\u5982\u00a0env&#061;prod\u3001env&#061;dev&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u6807\u6ce8\u7248\u672c&#xff08;\u5982\u00a0version&#061;v1.2.0&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u6309\u529f\u80fd\u5206\u7c7b&#xff08;\u5982\u00a0tier&#061;frontend\u3001component&#061;redis&#xff09;<\/p>\n<\/li>\n<\/ul>\n<p>\u6807\u7b7e\u53ef\u4ee5\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u6307\u5b9a&#xff0c;\u4e5f\u53ef\u4ee5\u540e\u7eed\u52a8\u6001\u6dfb\u52a0\u3001\u4fee\u6539\u3002<\/p>\n<h3>&#x1f6e0;\ufe0f \u5b9e\u8df5\u64cd\u4f5c<\/h3>\n<h4>\u6b65\u9aa4 1&#xff1a;\u521b\u5efa Service&#xff08;NodePort \u7c7b\u578b&#xff09;<\/h4>\n<p>\u4f7f\u7528\u00a0kubectl expose\u00a0\u547d\u4ee4\u4e3a Deployment \u521b\u5efa Service&#xff1a;<\/p>\n<p>kubectl expose deployment\/kubernetes-bootcamp &#8211;type&#061;&#034;NodePort&#034; &#8211;port 8080<\/p>\n<p>\u6b64\u547d\u4ee4\u4f1a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u00a0kubernetes-bootcamp\u00a0\u7684 Service&#xff0c;\u7c7b\u578b\u4e3a NodePort&#xff0c;\u5bb9\u5668\u7aef\u53e3\u4e3a 8080\u3002<\/p>\n<p>ccc&#064;cccs-MBP ~ % kubectl get services<\/p>\n<p>NAME \u00a0 \u00a0 \u00a0 \u00a0 TYPE \u00a0 \u00a0 \u00a0 \u00a0CLUSTER-IP \u00a0 EXTERNAL-IP \u00a0 PORT(S) \u00a0 AGE<br \/>\nkubernetes \u00a0 ClusterIP \u00a0 10.96.0.1 \u00a0 \u00a0&lt;none&gt; \u00a0 \u00a0 \u00a0 \u00a0443\/TCP \u00a0 20h<br \/>\nccc&#064;cccs-MBP ~ % <span style=\"background-color:#f9eda6\">kubectl expose deployment\/kubernetes-bootcamp &#8211;type&#061;&#034;NodePort&#034; &#8211;port 8080<\/span><\/p>\n<p>service\/kubernetes-bootcamp exposed<br \/>\nccc&#064;cccs-MBP ~ % kubectl get services \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/p>\n<p>NAME \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0TYPE \u00a0 \u00a0 \u00a0 \u00a0CLUSTER-IP \u00a0 \u00a0 \u00a0EXTERNAL-IP \u00a0 PORT(S) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0AGE<br \/>\nkubernetes \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0ClusterIP \u00a0 10.96.0.1 \u00a0 \u00a0 \u00a0 &lt;none&gt; \u00a0 \u00a0 \u00a0 \u00a0443\/TCP \u00a0 \u00a0 \u00a0 \u00a0 \u00a020h<br \/>\nkubernetes-bootcamp \u00a0 NodePort \u00a0 \u00a010.99.224.218 \u00a0 &lt;none&gt; \u00a0 \u00a0 \u00a0 \u00a08080:30848\/TCP \u00a0 8s<br \/>\nccc&#064;cccs-MBP ~ %<\/p>\n<p>\u67e5\u770b Service \u8be6\u60c5&#xff1a;<\/p>\n<p>kubectl describe services\/kubernetes-bootcamp<\/p>\n<p>\u8f93\u51fa\u4f1a\u663e\u793a Service \u7684\u96c6\u7fa4 IP\u3001\u5185\u90e8\u7aef\u53e3\u4ee5\u53ca\u8282\u70b9\u7aef\u53e3&#xff08;NodePort&#xff0c;\u8303\u56f4\u901a\u5e38\u4e3a 30000-32767&#xff09;\u3002<\/p>\n<p>ccc&#064;cccs-MBP ~ % kubectl describe services\/kubernetes-bootcamp<\/p>\n<p>Name: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 kubernetes-bootcamp<br \/>\nNamespace: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0default<br \/>\nLabels: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 app&#061;kubernetes-bootcamp<br \/>\nAnnotations: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&lt;none&gt;<br \/>\nSelector: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 app&#061;kubernetes-bootcamp<br \/>\nType: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 NodePort<br \/>\nIP Family Policy: \u00a0 \u00a0 \u00a0 \u00a0 SingleStack<br \/>\nIP Families: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0IPv4<br \/>\nIP: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 10.99.224.218<br \/>\nIPs: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a010.99.224.218<br \/>\nLoadBalancer Ingress: \u00a0 \u00a0 localhost<br \/>\nPort: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;unset&gt; \u00a08080\/TCP<br \/>\nTargetPort: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 8080\/TCP<br \/>\nNodePort: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;unset&gt; \u00a030848\/TCP<br \/>\nEndpoints: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a010.1.0.17:8080<br \/>\nSession Affinity: \u00a0 \u00a0 \u00a0 \u00a0 None<br \/>\nExternal Traffic Policy: \u00a0Cluster<br \/>\nEvents: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;none&gt;<br \/>\nccc&#064;cccs-MBP ~ %<\/p>\n<p>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u5e76\u6d4b\u8bd5\u8bbf\u95ee&#xff1a;<\/p>\n<p># \u63d0\u53d6\u8282\u70b9\u7aef\u53e3\u53f7<br \/>\nexport NODE_PORT&#061;$(kubectl get services\/kubernetes-bootcamp -o go-template&#061;&#039;{{(index .spec.ports 0).nodePort}}&#039;)<br \/>\necho &#034;NodePort: $NODE_PORT&#034;<\/p>\n<p># \u5728Docker Desktop\u4e2d\u53ef\u4ee5\u76f4\u63a5localhost\u6216127.0.0.1<br \/>\ncurl http:\/\/localhost:$NODE_PORT<\/p>\n<p>ccc&#064;cccs-MBP ~ % export NODE_PORT&#061;$(kubectl get services\/kubernetes-bootcamp -o go-template&#061;&#039;{{(index .spec.ports 0).nodePort}}&#039;)<br \/>\necho &#034;NodePort: $NODE_PORT&#034;<br \/>\nNodePort: 30848<br \/>\nccc&#064;cccs-MBP ~ % curl http:\/\/localhost:30848<br \/>\nHello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-75c5d958ff-flfdd | v&#061;1<br \/>\nccc&#064;cccs-MBP ~ %<\/p>\n<h4>\u6b65\u9aa4 2&#xff1a;\u4f7f\u7528\u6807\u7b7e\u8fdb\u884c\u67e5\u8be2\u548c\u7ba1\u7406<\/h4>\n<p>\u67e5\u770b Deployment \u81ea\u52a8\u521b\u5efa\u7684\u6807\u7b7e&#xff1a;<\/p>\n<p>kubectl describe deployment kubernetes-bootcamp<\/p>\n<p>\u901a\u5e38\u4f1a\u81ea\u52a8\u751f\u6210\u00a0app&#061;kubernetes-bootcamp\u00a0\u6807\u7b7e\u3002<\/p>\n<p>\u4f7f\u7528\u6807\u7b7e\u7b5b\u9009 Pod \u548c Service&#xff1a;<\/p>\n<p># \u67e5\u770b\u5e26\u6709\u7279\u5b9a\u6807\u7b7e\u7684 Pod<br \/>\nkubectl get pods -l app&#061;kubernetes-bootcamp<\/p>\n<p># \u67e5\u770b\u5e26\u6709\u7279\u5b9a\u6807\u7b7e\u7684 Service<br \/>\nkubectl get services -l app&#061;kubernetes-bootcamp<\/p>\n<p>\u4e3a Pod \u6dfb\u52a0\u65b0\u6807\u7b7e&#xff1a;<\/p>\n<p># \u83b7\u53d6 Pod \u540d\u79f0<br \/>\nexport POD_NAME&#061;$(kubectl get pods -o go-template &#8211;template &#039;{{range .items}}{{.metadata.name}}{{&#034;\\\\n&#034;}}{{end}}&#039;)<\/p>\n<p># \u6dfb\u52a0\u7248\u672c\u6807\u7b7e<br \/>\nkubectl label pods $POD_NAME version&#061;v1<\/p>\n<p># \u9a8c\u8bc1\u6807\u7b7e<br \/>\nkubectl describe pods $POD_NAME<\/p>\n<p># \u6309\u65b0\u6807\u7b7e\u67e5\u8be2<br \/>\nkubectl get pods -l version&#061;v1<\/p>\n<p>ccc&#064;cccs-MBP ~ % export POD_NAME&#061;&#034;$(kubectl get pods -o go-template &#8211;template &#039;{{range .items}}{{.metadata.name}}{{&#034;\\\\n&#034;}}{{end}}&#039;)&#034;<br \/>\necho &#034;Name of the Pod: $POD_NAME&#034;<br \/>\nName of the Pod: kubernetes-bootcamp-75c5d958ff-flfdd<br \/>\nccc&#064;cccs-MBP ~ % kubectl label pods &#034;$POD_NAME&#034; version&#061;v1<\/p>\n<p>pod\/kubernetes-bootcamp-75c5d958ff-flfdd labeled<br \/>\nccc&#064;cccs-MBP ~ % kubectl describe pods &#034;$POD_NAME&#034;<\/p>\n<p>Name:             kubernetes-bootcamp-75c5d958ff-flfdd<br \/>\nNamespace:        default<br \/>\nPriority:         0<br \/>\nService Account:  default<br \/>\nNode:             docker-desktop\/192.168.65.4<br \/>\nStart Time:       Fri, 30 Jan 2026 09:18:24 &#043;0800<br \/>\nLabels:           app&#061;kubernetes-bootcamp<br \/>\n                  pod-template-hash&#061;75c5d958ff<br \/>\n                  version&#061;v1<br \/>\nAnnotations:      &lt;none&gt;<br \/>\nStatus:           Running<br \/>\nIP:               10.1.0.17<br \/>\nIPs:<br \/>\n  IP:           10.1.0.17<br \/>\nControlled By:  ReplicaSet\/kubernetes-bootcamp-75c5d958ff<br \/>\nContainers:<br \/>\n  kubernetes-bootcamp:<br \/>\n    Container ID:   docker:\/\/42746c7a21be846354d7c4f0f33a364efcfd9cc4f5353907c1b9912e106beeb0<br \/>\n    Image:          gcr.io\/google-samples\/kubernetes-bootcamp:v1<br \/>\n    Image ID:       docker-pullable:\/\/gcr.io\/google-samples\/kubernetes-bootcamp&#064;sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af<br \/>\n    Port:           &lt;none&gt;<br \/>\n    Host Port:      &lt;none&gt;<br \/>\n    State:          Running<br \/>\n      Started:      Fri, 30 Jan 2026 09:18:25 &#043;0800<br \/>\n    Ready:          True<br \/>\n    Restart Count:  0<br \/>\n    Environment:    &lt;none&gt;<br \/>\n    Mounts:<br \/>\n      \/var\/run\/secrets\/kubernetes.io\/serviceaccount from kube-api-access-s64m8 (ro)<br \/>\nConditions:<br \/>\n  Type              Status<br \/>\n  Initialized       True<br \/>\n  Ready             True<br \/>\n  ContainersReady   True<br \/>\n  PodScheduled      True<br \/>\nVolumes:<br \/>\n  kube-api-access-s64m8:<br \/>\n    Type:                    Projected (a volume that contains injected data from multiple sources)<br \/>\n    TokenExpirationSeconds:  3607<br \/>\n    ConfigMapName:           kube-root-ca.crt<br \/>\n    ConfigMapOptional:       &lt;nil&gt;<br \/>\n    DownwardAPI:             true<br \/>\nQoS Class:                   BestEffort<br \/>\nNode-Selectors:              &lt;none&gt;<br \/>\nTolerations:                 node.kubernetes.io\/not-ready:NoExecute op&#061;Exists for 300s<br \/>\n                             node.kubernetes.io\/unreachable:NoExecute op&#061;Exists for 300s<br \/>\nEvents:                      &lt;none&gt;<br \/>\nccc&#064;cccs-MBP ~ % kubectl get pods -l version&#061;v1<\/p>\n<p>NAME                                   READY   STATUS    RESTARTS   AGE<br \/>\nkubernetes-bootcamp-75c5d958ff-flfdd   1\/1     Running   0          132m<br \/>\nccc&#064;cccs-MBP ~ %<\/p>\n<h4>\u6b65\u9aa4 3&#xff1a;\u5220\u9664 Service<\/h4>\n<p>\u901a\u8fc7\u6807\u7b7e\u5220\u9664 Service&#xff1a;<\/p>\n<p>kubectl delete service -l app&#061;kubernetes-bootcamp<\/p>\n<p>\u9a8c\u8bc1\u5220\u9664\u7ed3\u679c&#xff1a;<\/p>\n<p>kubectl get services<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5220\u9664 Service \u4ec5\u79fb\u9664\u4e86\u8bbf\u95ee\u5165\u53e3&#xff0c;\u4e0d\u4f1a\u5220\u9664 Pod\u3002\u5e94\u7528\u4ecd\u53ef\u5728\u96c6\u7fa4\u5185\u90e8\u8fd0\u884c&#xff0c;\u53ef\u901a\u8fc7\u8fdb\u5165 Pod \u5185\u90e8\u9a8c\u8bc1&#xff1a;<\/p>\n<p>kubectl exec -ti $POD_NAME &#8212; curl http:\/\/localhost:8080<\/p>\n<p>\u82e5\u8981\u5b8c\u5168\u5173\u95ed\u5e94\u7528&#xff0c;\u9700\u8981\u5220\u9664\u5bf9\u5e94\u7684 Deployment\u3002<\/p>\n<h3>&#x1f4ca; \u603b\u7ed3<\/h3>\n<table>\n<tr>\u64cd\u4f5c\u547d\u4ee4\u793a\u4f8b\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u521b\u5efa NodePort Service<\/td>\n<td>kubectl expose deployment\/&lt;\u540d\u79f0&gt; &#8211;type&#061;NodePort &#8211;port &lt;\u7aef\u53e3&gt;<\/td>\n<td>\u66b4\u9732\u5e94\u7528\u5230\u96c6\u7fa4\u5916\u90e8<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u770b Service \u8be6\u60c5<\/td>\n<td>kubectl describe services\/&lt;\u540d\u79f0&gt;<\/td>\n<td>\u67e5\u770b IP\u3001\u7aef\u53e3\u3001\u9009\u62e9\u5668\u7b49\u8be6\u7ec6\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td>\u6309\u6807\u7b7e\u7b5b\u9009\u5bf9\u8c61<\/td>\n<td>kubectl get pods -l &lt;\u952e&gt;&#061;&lt;\u503c&gt;<\/td>\n<td>\u67e5\u8be2\u5e26\u6709\u7279\u5b9a\u6807\u7b7e\u7684 Pod\/Service<\/td>\n<\/tr>\n<tr>\n<td>\u6dfb\u52a0\u6807\u7b7e<\/td>\n<td>kubectl label pods &lt;\u540d\u79f0&gt; &lt;\u952e&gt;&#061;&lt;\u503c&gt;<\/td>\n<td>\u4e3a\u5df2\u6709\u5bf9\u8c61\u6dfb\u52a0\u6216\u66f4\u65b0\u6807\u7b7e<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664 Service<\/td>\n<td>kubectl delete service -l &lt;\u952e&gt;&#061;&lt;\u503c&gt;<\/td>\n<td>\u901a\u8fc7\u6807\u7b7e\u5220\u9664 Service&#xff08;\u4e0d\u5f71\u54cd Pod&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>&#x1f50d; \u8865\u5145\u8bf4\u660e<\/h3>\n<ul>\n<li>\n<p>\u65e0\u9009\u62e9\u5668\u7684 Service&#xff1a;\u53ef\u4ee5\u521b\u5efa\u4e0d\u5b9a\u4e49\u00a0selector\u00a0\u7684 Service&#xff0c;\u6b64\u65f6\u4e0d\u4f1a\u81ea\u52a8\u521b\u5efa Endpoints&#xff0c;\u9700\u624b\u52a8\u5173\u8054\u7279\u5b9a\u7aef\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>ExternalName \u7c7b\u578b&#xff1a;\u4ec5\u7528\u4e8e DNS \u6620\u5c04&#xff0c;\u4e0d\u8fdb\u884c\u6d41\u91cf\u4ee3\u7406&#xff0c;\u9002\u5408\u96c6\u6210\u5916\u90e8\u670d\u52a1\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d1f\u8f7d\u5747\u8861&#xff1a;Service \u9ed8\u8ba4\u5728\u5339\u914d\u7684 Pod \u95f4\u8fdb\u884c\u4f1a\u8bdd\u65e0\u5173\u7684\u8f6e\u8be2\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u00a0Service\u00a0\u66b4\u9732\u5e94\u7528\u3001\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0&#xff0c;\u5e76\u7ba1\u7406\u76f8\u5173\u6807\u7b7e\u3002&#x1f4cc; \u6838\u5fc3\u6982\u5ff5&#xff1a;Kubernetes Service\u4ec0\u4e48\u662f Service&#xff1f;Pod \u662f\u6709\u751f\u547d\u5468\u671f\u7684&#xff0c;\u5f53\u8282\u70b9\u6545\u969c\u6216\u88ab\u66ff\u6362\u65f6&#xff0c;\u5176\u4e0a\u7684 Pod \u4f1a\u968f\u4e4b\u6d88\u4ea1&#xff0c;\u5e76\u7531 ReplicaSet \u7b49\u63a7\u5236\u5668\u521b\u5efa\u65b0 Pod \u6765\u66ff\u6362\u3002\u8fd9\u4e9b\u65b0 Pod \u4f1a\u5206\u914d\u65b0\u7684 IP \u5730\u5740\u3002Service \u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u7531\u6b64\u4ea7\u751f\u7684\u670d\u52a1\u53d1\u73b0\u4e0e<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[120,763,121],"topic":[],"class_list":["post-69370","post","type-post","status-publish","format-standard","hentry","category-server","tag-kubernetes","tag-763","tag-121"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/69370.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u00a0Service\u00a0\u66b4\u9732\u5e94\u7528\u3001\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0&#xff0c;\u5e76\u7ba1\u7406\u76f8\u5173\u6807\u7b7e\u3002&#x1f4cc; \u6838\u5fc3\u6982\u5ff5&#xff1a;Kubernetes Service\u4ec0\u4e48\u662f Service&#xff1f;Pod \u662f\u6709\u751f\u547d\u5468\u671f\u7684&#xff0c;\u5f53\u8282\u70b9\u6545\u969c\u6216\u88ab\u66ff\u6362\u65f6&#xff0c;\u5176\u4e0a\u7684 Pod \u4f1a\u968f\u4e4b\u6d88\u4ea1&#xff0c;\u5e76\u7531 ReplicaSet \u7b49\u63a7\u5236\u5668\u521b\u5efa\u65b0 Pod \u6765\u66ff\u6362\u3002\u8fd9\u4e9b\u65b0 Pod \u4f1a\u5206\u914d\u65b0\u7684 IP \u5730\u5740\u3002Service \u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u7531\u6b64\u4ea7\u751f\u7684\u670d\u52a1\u53d1\u73b0\u4e0e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69370.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-31T07:40:51+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69370.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69370.html\",\"name\":\"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-31T07:40:51+00:00\",\"dateModified\":\"2026-01-31T07:40:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69370.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69370.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69370.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/69370.html","og_locale":"zh_CN","og_type":"article","og_title":"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u00a0Service\u00a0\u66b4\u9732\u5e94\u7528\u3001\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0&#xff0c;\u5e76\u7ba1\u7406\u76f8\u5173\u6807\u7b7e\u3002&#x1f4cc; \u6838\u5fc3\u6982\u5ff5&#xff1a;Kubernetes Service\u4ec0\u4e48\u662f Service&#xff1f;Pod \u662f\u6709\u751f\u547d\u5468\u671f\u7684&#xff0c;\u5f53\u8282\u70b9\u6545\u969c\u6216\u88ab\u66ff\u6362\u65f6&#xff0c;\u5176\u4e0a\u7684 Pod \u4f1a\u968f\u4e4b\u6d88\u4ea1&#xff0c;\u5e76\u7531 ReplicaSet \u7b49\u63a7\u5236\u5668\u521b\u5efa\u65b0 Pod \u6765\u66ff\u6362\u3002\u8fd9\u4e9b\u65b0 Pod \u4f1a\u5206\u914d\u65b0\u7684 IP \u5730\u5740\u3002Service \u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u7531\u6b64\u4ea7\u751f\u7684\u670d\u52a1\u53d1\u73b0\u4e0e","og_url":"https:\/\/www.wsisp.com\/helps\/69370.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-31T07:40:51+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69370.html","url":"https:\/\/www.wsisp.com\/helps\/69370.html","name":"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-31T07:40:51+00:00","dateModified":"2026-01-31T07:40:51+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69370.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69370.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69370.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Kubernetes\u57fa\u7840\u5165\u95e83 \u4f7f\u7528 Service \u5b9e\u73b0\u5916\u90e8\u8bbf\u95ee"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=69370"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69370\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69370"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}