{"id":6108,"date":"2024-08-01T22:48:59","date_gmt":"2024-08-01T14:48:59","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6108"},"modified":"2024-08-02T15:40:22","modified_gmt":"2024-08-02T07:40:22","slug":"%e4%b8%80%e7%af%87%e6%96%87%e7%ab%a0%e7%b2%be%e9%80%9ak8s%e7%9a%84%e7%bb%9f%e4%b8%80%e8%ae%bf%e9%97%ae%e5%85%a5%e5%8f%a3-service","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/k8s\/%e4%b8%80%e7%af%87%e6%96%87%e7%ab%a0%e7%b2%be%e9%80%9ak8s%e7%9a%84%e7%bb%9f%e4%b8%80%e8%ae%bf%e9%97%ae%e5%85%a5%e5%8f%a3-service\/","title":{"rendered":"\u4e00\u7bc7\u6587\u7ae0\u7cbe\u901aK8S\u7684\u7edf\u4e00\u8bbf\u95ee\u5165\u53e3-Service"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<section style=\"margin-bottom: unset;\">\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32578\">\n<section style=\"margin: 10px 0px; text-align: left;\" data-align=\"title\">\n<section style=\"border-left: 3px solid #205792; padding: 0px 0px 0px 4px; margin-bottom: unset; box-sizing: border-box;\">\n<section style=\"background-color: #f1f1f1; padding: 2px 10px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">Service\u662f\u4ec0\u4e48?<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 1.2em; line-height: 1.7; color: #00323c; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 16px; letter-spacing: normal;\">\n<li>\u80cc\u666f\uff1a\u6bcf\u4e2aPod\u5177\u6709IP\u5730\u5740\uff0c\u5f53\u4f7f\u7528Deployment\u63a7\u5236\u5668\u65f6\uff0cPod\u7684IP\u5730\u5740\u5f80\u5f80\u52a8\u6001\u53d8\u5316\u3002<\/li>\n<li>\u89e3\u51b3\u65b9\u6cd5\uff1a\u901a\u8fc7Service\u53ef\u4ee5\u83b7\u5f97\u7a33\u5b9a\u7684IP\u5730\u5740\uff0c\u4e14\u5728Service\u7684\u751f\u547d\u5468\u671f\u6709\u6548\uff0c\u4e0ePod\u7684IP\u5730\u5740\u53d8\u5316\u4e0e\u5426\u65e0\u5173\u3002<\/li>\n<li>\u5b9e\u8d28\uff1aService\u672c\u8d28\u5c31\u662f\u4e00\u4e2aLB\u8d1f\u8f7d\u5747\u8861\u5668<\/li>\n<\/ul>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32578\">\n<section style=\"margin: 10px 0px; text-align: left;\" data-align=\"title\">\n<section style=\"border-left: 3px solid #205792; padding: 0px 0px 0px 4px; box-sizing: border-box; margin-bottom: unset;\">\n<section style=\"background-color: #f1f1f1; padding: 2px 10px; letter-spacing: 2px; color: #000000; font-size: 16px; box-sizing: border-box; margin-bottom: unset;\">Service\u5b58\u5728\u7684\u610f\u4e49<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223545119.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.325\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223545119.png\" data-ratio=\"0.325\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32578\">\n<section style=\"margin: 10px 0px; text-align: left;\" data-align=\"title\">\n<section style=\"border-left: 3px solid #205792; padding: 0px 0px 0px 4px; margin-bottom: unset; box-sizing: border-box;\">\n<section style=\"background-color: #f1f1f1; padding: 2px 10px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">Pod\u4e0eService\u7684\u5173\u7cfb<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223551511.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.3\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223551511.png\" data-ratio=\"0.3\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32578\">\n<section style=\"margin: 10px 0px; text-align: left;\" data-align=\"title\">\n<section style=\"border-left: 3px solid #205792; padding: 0px 0px 0px 4px; margin-bottom: unset; box-sizing: border-box;\">\n<section style=\"background-color: #f1f1f1; padding: 2px 10px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">Service\u5b9a\u4e49\u548c\u521b\u5efa<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223558674.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.5441176470588235\" data-w=\"1020\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223558674.png\" data-ratio=\"0.5441176470588235\" data-w=\"1020\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">\u521b\u5efaNginx<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# vim deployment.yaml<\/span><\/code><code class=\"code-snippet_outer\"><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">apiVersion: apps\/v1<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kind: Deployment<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> name: nginx-deployment<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> labels:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  app: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> replicas: 3<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> selector:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  matchLabels:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   app: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> template:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   labels:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    app: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   containers:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   - name: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    image: nginx:1.14.2<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    ports:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    - containerPort: 80<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"text-align: start;\"><span style=\"color: #00323c; font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;\"><span style=\"font-size: 16px; letter-spacing: normal;\">\u67e5\u770b\u521a\u521a\u90e8\u7f72\u7684Nginx\u670d\u52a1\u6807\u7b7e<\/span><\/span><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"yaml\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl get pods --show-labels<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">NAME            READY  STATUS  RESTARTS   AGE  LABELS<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-6799fc88d8-s5rnz      1\/1  Running  0     24d  app=nginx,pod-template-hash=6799fc88d8<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-deployment-66b6c48dd5-hxv7h  1\/1   Running  0     70s  app=nginx,pod-template-hash=66b6c48dd5<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-deployment-66b6c48dd5-jjkk4  1\/1   Running  0     70s  app=nginx,pod-template-hash=66b6c48dd5<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-deployment-66b6c48dd5-tsgvb  1\/1   Running  0     70s  app=nginx,pod-template-hash=66b6c48dd5<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\u67e5\u770b\u5f53\u524dnamespace(default)\u4e0b\u6709\u54ea\u4e9bsvc<\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"bash\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl get svc<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">NAME     TYPE   CLUSTER-IP  EXTERNAL-IP  PORT(S)    AGE<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kubernetes  ClusterIP   10.96.0.1   &lt;none&gt;    443\/TCP    24d<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx    NodePort  10.108.41.4  &lt;none&gt;    80:31434\/TCP  24d<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">\u5b9a\u4e49\u5e76\u521b\u5efaService<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-node2 ~]# vim service.yaml<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">apiVersion: v1<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kind: Service<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> name: web<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> namespace: default<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> ports:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> - port: 80    # Service\u7aef\u53e3<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  protocol: TCP  # \u534f\u8bae<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  targetPort: 80  # \u5bb9\u5668\u7aef\u53e3\uff08\u7a0b\u5e8f\u542f\u52a8\u7aef\u53e3\uff0c\u6bd4\u5982django\u9ed8\u8ba4\u662f8000\u7aef\u53e3\uff09<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> selector: <\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  app: nginx   # \u6307\u5b9a\u5173\u8054Pod\u7684\u6807\u7b7e\uff08\u4e0a\u9762\u5df2\u7ecf\u67e5\u5230\u4e86\uff0capp=nginx\uff09<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> type: ClusterIP   # \u670d\u52a1\u7c7b\u578b<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\u521b\u5efasvc<\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl apply -f service.yaml<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">\u901a\u8fc7Service\u8bbf\u95eeNginx\u96c6\u7fa4<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl get svc<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">NAME     TYPE    CLUSTER-IP   EXTERNAL-IP  PORT(S)    AGE<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kubernetes  ClusterIP  10.96.0.1    &lt;none&gt;   443\/TCP    24d<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx    NodePort  10.108.41.4   &lt;none&gt;   80:31434\/TCP  24d<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">web     ClusterIP  10.105.53.183   &lt;none&gt;    80\/TCP    2m40s<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# curl 10.105.53.183    # \u53ef\u4ee5\u901a\u8fc7web\u7684\u5730\u5740\u8bbf\u95ee\u540e\u9762\u4e09\u4e2anginx\u96c6\u7fa4<\/span><\/code><code class=\"code-snippet_outer\"><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl delete svc web2   # \u53ef\u4ee5\u5220\u9664\u5176\u4e2d\u4e00\u4e2a<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32578\">\n<section style=\"margin: 10px 0px; text-align: left;\" data-align=\"title\">\n<section style=\"border-left: 3px solid #205792; padding: 0px 0px 0px 4px; margin-bottom: unset; box-sizing: border-box;\">\n<section style=\"background-color: #f1f1f1; padding: 2px 10px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">Service\u4e09\u79cd\u5e38\u7528\u7c7b\u578b<\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 1.2em; line-height: 1.7; color: #00323c; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 16px; letter-spacing: normal;\">\n<li>\n<p style=\"line-height: 1.7;\"><span style=\"font-weight: 600; color: #007aaa;\"><code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; color: var(--textlightencolor); padding: 0.25rem 0.5rem; font-size: 0.9em; background-color: #64646414; border-radius: 3px;\">ClusterIP<\/code>\uff1a\u96c6\u7fa4\u5185\u90e8\u4f7f\u7528<\/span><\/p>\n<\/li>\n<li>\n<p style=\"line-height: 1.7;\"><span style=\"font-weight: 600; color: #007aaa;\"><code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; color: var(--textlightencolor); padding: 0.25rem 0.5rem; font-size: 0.9em; background-color: #64646414; border-radius: 3px;\">NodePort<\/code>\uff1a\u5bf9\u5916\u66b4\u9732\u5e94\u7528\uff08\u96c6\u7fa4\u5916\uff09<\/span><\/p>\n<\/li>\n<li>\n<p style=\"line-height: 1.7;\"><span style=\"font-weight: 600; color: #007aaa;\"><code style=\"font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; color: var(--textlightencolor); padding: 0.25rem 0.5rem; font-size: 0.9em; background-color: #64646414; border-radius: 3px;\">LoadBalancer<\/code>\uff1a\u5bf9\u5916\u66b4\u9732\u5e94\u7528\uff0c\u9002\u7528\u516c\u6709\u4e91<\/span><\/p>\n<\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">ClusterIP(VIP)<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223605293.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.43703703703703706\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223605293.png\" data-ratio=\"0.43703703703703706\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">NodePort<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223610414.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.5203703703703704\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223610414.png\" data-ratio=\"0.5203703703703704\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">\u90e8\u7f72\u5e76\u6d4b\u8bd5<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# vim deployment.yaml<\/span><\/code><code class=\"code-snippet_outer\"><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">apiVersion: apps\/v1<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kind: Deployment<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> name: nginx-deployment<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> labels:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  app: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> replicas: 3<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> selector:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  matchLabels:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   app: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> template:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   labels:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    app: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   containers:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">   - name: nginx<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    image: nginx:1.14.2<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    ports:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    - containerPort: 80<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\u67e5\u770bnginx\u670d\u52a1\u7684\u6807\u7b7e<\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl get pods --show-labels<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">NAME            READY  STATUS  RESTARTS   AGE  LABELS<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-6799fc88d8-s5rnz      1\/1  Running  0     24d  app=nginx,pod-template-hash=6799fc88d8<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-deployment-66b6c48dd5-hxv7h  1\/1   Running  0     70s  app=nginx,pod-template-hash=66b6c48dd5<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-deployment-66b6c48dd5-jjkk4  1\/1   Running  0     70s  app=nginx,pod-template-hash=66b6c48dd5<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">nginx-deployment-66b6c48dd5-tsgvb  1\/1   Running  0     70s  app=nginx,pod-template-hash=66b6c48dd5<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\u4f7f\u7528NodePort\u521b\u5efasvc<\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-node2 ~]# vim service-nodeport.yaml<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">apiVersion: v1<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kind: Service<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> name: web-nodeport<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> namespace: default<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> ports:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> - port: 80    # Service\u7aef\u53e3<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  protocol: TCP  # \u534f\u8bae<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  targetPort: 80  # \u5bb9\u5668\u7aef\u53e3\uff08\u7a0b\u5e8f\u542f\u52a8\u7aef\u53e3\uff0c\u6bd4\u5982django\u9ed8\u8ba4\u662f8000\u7aef\u53e3\uff09<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  nodePort: 30706  # \u6307\u5b9aNodePort\u76d1\u542c\u7684\u5916\u7f51\u7aef\u53e3<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> selector: <\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  app: nginx   # \u6307\u5b9a\u5173\u8054Pod\u7684\u6807\u7b7e\uff08\u4e0a\u9762\u5df2\u7ecf\u67e5\u5230\u4e86\uff0capp=nginx\uff09<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> type: NodePort   # \u670d\u52a1\u7c7b\u578b(\u53ea\u9700\u8981\u628a\u670d\u52a1\u7c7b\u578b\u4fee\u6539\u6210NodePort\u5373\u53ef)<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\u521b\u5efasvc<\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">[root@k8s-master ~]# kubectl apply -f service-nodeport.yaml<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\"><strong>\u8bbf\u95ee<\/strong><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 1.2em; line-height: 1.7; color: #00323c; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 16px; letter-spacing: normal;\">\n<li>\n<p style=\"line-height: 1.7;\">\u8bbf\u95ee\u5730\u5740\uff1a&lt;\u4efb\u610fNodeIP&gt;:NodePort<\/p>\n<\/li>\n<li>\n<p style=\"line-height: 1.7;\">\u7aef\u53e3\u8303\u56f4\uff1a30000-32767<\/p>\n<\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223618451.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.48592411260709917\" data-w=\"817\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223618451.png\" data-ratio=\"0.48592411260709917\" data-w=\"817\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><span style=\"text-decoration: underline;\"><strong>NodePort\u5f0a\u7aef<\/strong><\/span><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223625704.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.45\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223625704.png\" data-ratio=\"0.45\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">LoadBalancer<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><strong>LB\u8bf4\u660e<\/strong><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 1.2em; line-height: 1.7; color: #00323c; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 16px; letter-spacing: normal;\">\n<li>\n<p style=\"line-height: 1.7;\">\u8d1f\u8d23\u5747\u8861\u5668\u6709\u54ea\u4e9b\uff1anginx\u3001LVS\u3001haproxy<\/p>\n<\/li>\n<li>\n<p style=\"line-height: 1.7;\">\u79c1\u6709\u4e91\uff1aSLB\u3001ELB<\/p>\n<\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"vertical-align: bottom;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223633200.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.4546296296296296\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"vertical-align: bottom;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223633200.png\" data-ratio=\"0.4546296296296296\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><strong>\u914d\u7f6eLB<\/strong><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 1.2em; line-height: 1.7; color: #00323c; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; font-size: 16px; letter-spacing: normal;\">\n<li>\u76f4\u63a5\u627e\u4e00\u4e2anginx\u914d\u7f6e\u53cd\u5411\u4ee3\u7406\u5373\u53ef<\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">stream {<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent';<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  access_log \/var\/log\/nginx\/django-access.log main;<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  upstream django-apiserver {<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">        server 192.168.56.62:30706;<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">        server 192.168.56.63:30706;<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">      }<\/span><\/code><code class=\"code-snippet_outer\">  <\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  server {<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    listen 88;<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">    proxy_pass django-apiserver;<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  }<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">}<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><span style=\"font-weight: bold; font-size: 14px; letter-spacing: 2px; line-height: 1.75em; color: #ff0000; text-decoration: underline;\">\u6ce8\u610f\uff1a\u751f\u4ea7\u6700\u597d\u4f7f\u7528\u4e91\u5382\u5546\u7684ELB\u6216\u8005SLB<\/span><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32578\">\n<section style=\"margin: 10px 0px; text-align: left;\" data-align=\"title\">\n<section style=\"border-left: 3px solid #205792; padding: 0px 0px 0px 4px; margin-bottom: unset; box-sizing: border-box;\">\n<section style=\"background-color: #f1f1f1; padding: 2px 10px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\"><strong>Service\u4e8c\u79cd\u7279\u6b8a\u7c7b\u578b<\/strong><\/p>\n<\/section>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 1.2em; line-height: 1.7; color: #00323c; letter-spacing: normal;\">\n<li>\n<p style=\"line-height: 1.7;\"><span style=\"font-size: 15px;\"><strong><span style=\"font-weight: 600; color: #007aaa; font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; background-color: #64646414;\">ExternalName<\/span><\/strong><span style=\"font-weight: 600; color: #007aaa;\"><span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;\">\uff1a\u5f15\u7528\u96c6\u7fa4\u5916\u7684\u670d\u52a1<\/span><\/span><\/span><\/p>\n<\/li>\n<li>\n<p style=\"line-height: 1.7;\"><span style=\"font-weight: 600; color: #007aaa;\"><span style=\"font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 15.309px; background-color: rgba(100, 100, 100, 0.08);\">Headless<\/span>\uff1a<span style=\"font-weight: 600; color: #007aaa; font-size: 15px;\">\u5141\u8bb8Pod\u901a\u8fc7\u5176\u4e3b\u673a\u540d\u88ab\u8bbf\u95ee<\/span><\/span><\/p>\n<\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">ExternalName Service<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<h3 style=\"box-sizing: inherit; margin-block: 0.67em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start;\"><strong><span style=\"font-weight: bold; letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">ExternalName Service\u8bf4\u660e:<\/span><\/strong><\/h3>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"text-indent: 2em;\"><strong><code style=\"box-sizing: inherit; overflow: auto; white-space-collapse: preserve; color: #060607; margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); font-size: 14px; letter-spacing: 0.5px; word-break: break-word !important;\"><span style=\"font-size: 16px; color: #007aaa; font-family: monospace;\">ExternalName<\/span><\/code><span style=\"font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve; font-size: 16px; color: #007aaa;\"> Service<\/span><\/strong><span style=\"font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve; font-size: 16px; color: #007aaa;\"> \u662f\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684 Service\uff0c\u5b83\u4e0d\u5206\u914d ClusterIP\uff0c\u4e5f\u4e0d\u9009\u62e9 Pods\u3002\u76f8\u53cd\uff0c\u5b83\u5141\u8bb8\u4f60\u901a\u8fc7 Kubernetes Service \u6765\u5f15\u7528\u5916\u90e8\u7684\u670d\u52a1\uff0c\u6bd4\u5982\u4e00\u4e2a\u6258\u7ba1\u5728\u96c6\u7fa4\u5916\u7684\u6570\u636e\u5e93\u6216\u4efb\u4f55\u5176\u4ed6\u670d\u52a1\u3002<\/span><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><strong><span style=\"font-weight: bold; letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">\u4f7f\u7528\u573a\u666f\uff1a<\/span><\/strong><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<ul class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li>\u5f15\u7528\u96c6\u7fa4\u5916\u7684\u670d\u52a1\u3002<\/li>\n<li>\u7b80\u5316\u5bf9\u5916\u90e8\u670d\u52a1\u7684\u5f15\u7528\uff0c\u4e0d\u9700\u8981\u4fee\u6539\u5e94\u7528\u7a0b\u5e8f\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><strong><span style=\"font-weight: bold; letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">\u64cd\u4f5c\u6b65\u9aa4\uff1a<\/span><\/strong><\/p>\n<ol class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li>\u521b\u5efa\u4e00\u4e2a<code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\">ExternalName<\/code>\u7c7b\u578b\u7684 Service YAML \u6587\u4ef6\uff0c\u6307\u5b9a<code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\">type: ExternalName<\/code>\u548c<code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\">externalName<\/code>\u5b57\u6bb5\u3002<\/li>\n<li>\u5e94\u7528\u8be5 YAML \u6587\u4ef6\u6765\u521b\u5efa Service\u3002<\/li>\n<\/ol>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">apiVersion: v1<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">kind: Service<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">metadata:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> name: external-db-service<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">spec:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> type: ExternalName<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> externalName: my.database.com<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> ports:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> - port: 5432<\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><strong><span style=\"font-weight: bold; letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">\u5b9e\u73b0\u6548<\/span><\/strong><strong><span style=\"font-weight: bold; letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">\u679c\uff1a<\/span><\/strong><\/p>\n<ul class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\">\u5f53\u4f60\u521b\u5efa\u4e86\u4e0a\u8ff0 Service \u540e\uff0cKubernetes \u4f1a\u521b\u5efa\u4e00\u4e2a DNS \u8bb0\u5f55\uff0c\u4f7f\u5f97<\/span><strong><span style=\"color: #007aaa; background-color: #d6d6d6;\"><code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"color: #007aaa; font-size: 16px; background-color: #d6d6d6;\">external-db-service.default.svc.cluster.local<\/span><\/code><\/span><\/strong><span style=\"font-size: 16px;\">\u89e3\u6790\u5230<\/span><strong><code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px; background-color: #d6d6d6; color: #007aaa;\">my.database.com<\/span><\/code><\/strong><span style=\"font-size: 16px;\">\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\">\u96c6\u7fa4\u5185\u7684 Pod \u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a DNS \u540d\u79f0\u548c\u7aef\u53e3\u53f7<\/span><code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\">5432<\/span><\/code><span style=\"font-size: 16px;\">\u6765\u8bbf\u95ee\u5916\u90e8\u7684\u6570\u636e\u5e93\u670d\u52a1\u3002<\/span><\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<h3 style=\"box-sizing: inherit; margin-block: 0.67em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start;\"><strong><span style=\"font-weight: bold; letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">ExternalName Service \u4f18\u7f3a\u70b9\uff1a<\/span><\/strong><\/h3>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold;\">\u4f18\u70b9<\/span>\uff1a<\/span><\/p>\n<ol class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u7b80\u5316\u5916\u90e8\u670d\u52a1\u5f15\u7528<\/span>\uff1a\u4e0d\u9700\u8981\u4fee\u6539\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u5373\u53ef\u5f15\u7528\u5916\u90e8\u670d\u52a1\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u96c6\u6210\u5916\u90e8\u670d\u52a1<\/span>\uff1a\u53ef\u4ee5\u65e0\u7f1d\u5730\u5c06\u5916\u90e8\u670d\u52a1\u96c6\u6210\u5230Kubernetes\u96c6\u7fa4\u7684\u670d\u52a1\u53d1\u73b0\u673a\u5236\u4e2d\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u7075\u6d3b\u6027<\/span>\uff1a\u53ef\u4ee5\u5f15\u7528\u4efb\u4f55\u53ef\u901a\u8fc7DNS\u89e3\u6790\u7684\u670d\u52a1\uff0c\u4e0d\u9650\u4e8e\u7279\u5b9a\u7684\u670d\u52a1\u7c7b\u578b\u6216\u534f\u8bae\u3002<\/span><\/li>\n<\/ol>\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u7f3a\u70b9<\/span>\uff1a<\/span><\/p>\n<ol class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u4f9d\u8d56\u5916\u90e8\u670d\u52a1<\/span>\uff1a\u5982\u679c\u5916\u90e8\u670d\u52a1\u4e0d\u53ef\u7528\uff0c\u90a3\u4e48\u901a\u8fc7<\/span><code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\">ExternalName<\/span><\/code><span style=\"font-size: 16px;\">Service \u8bbf\u95ee\u5b83\u4e5f\u4f1a\u5931\u8d25\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u6ca1\u6709\u8d1f\u8f7d\u5747\u8861<\/span>\uff1a\u4e0d\u63d0\u4f9b\u5185\u7f6e\u7684\u8d1f\u8f7d\u5747\u8861\u529f\u80fd\uff0c\u6240\u6709\u6d41\u91cf\u76f4\u63a5\u8f6c\u53d1\u5230\u5916\u90e8\u670d\u52a1\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u5b89\u5168\u6027<\/span>\uff1a\u5982\u679c\u5916\u90e8\u670d\u52a1\u9700\u8981\u7279\u5b9a\u7684\u5b89\u5168\u63aa\u65bd\uff0c\u53ef\u80fd\u9700\u8981\u989d\u5916\u7684\u914d\u7f6e\u3002<\/span><\/li>\n<\/ol>\n<\/section>\n<section style=\"margin-bottom: unset;\" data-support=\"96\u7f16\u8f91\u5668\" data-style-id=\"32577\">\n<section style=\"margin: 10px 0px; text-align: left;\">\n<section style=\"display: inline-block; margin-bottom: unset;\">\n<section style=\"margin: 0px 6px; display: flex; align-items: center;\">\n<section style=\"width: 4px; height: 16px; background-color: #205792; margin-bottom: unset; overflow: hidden; line-height: 0;\"><\/section>\n<section style=\"padding: 0px 8px; letter-spacing: 2px; color: #000000; font-size: 16px; margin-bottom: unset; box-sizing: border-box;\">Headless Service<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section style=\"margin: 1px 0px 0px; width: 100%; height: 1px; background-color: #d1d1d1; overflow: hidden; line-height: 0;\" data-width=\"100%\"><\/section>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<h3 style=\"box-sizing: inherit; margin-block: 0.67em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start;\"><strong><span style=\"letter-spacing: 0.57834px; line-height: 27.216px; font-size: 16px; color: #060607;\">Headless Service\u8bf4\u660e:<\/span><\/strong><\/h3>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"text-indent: 2em;\"><strong><code style=\"box-sizing: inherit; overflow: auto; white-space-collapse: preserve; color: #060607; margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); font-size: 14px; letter-spacing: 0.5px; word-break: break-word !important;\"><span style=\"font-size: 16px; color: #007aaa;\">Headless Service<\/span><\/code> <\/strong><span style=\"font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve; font-size: 16px; color: #007aaa;\">\u662f\u4e00\u79cd\u4e0d\u5206\u914d ClusterIP \u7684 Service\uff0c\u5b83\u5141\u8bb8\u6bcf\u4e2a Pod \u901a\u8fc7\u5176\u4e3b\u673a\u540d\u76f4\u63a5\u88ab\u8bbf\u95ee\u3002<\/span><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><strong><span style=\"color: #060607; font-weight: bold; letter-spacing: 0.5px; line-height: 22.4px;\">\u4f7f\u7528\u573a\u666f\uff1a<\/span><\/strong><\/span><\/p>\n<ul class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\">\u5f53\u4f60\u4e0d\u9700\u8981 Kubernetes \u6765\u7ba1\u7406\u8d1f\u8f7d\u5747\u8861\u548c\u8def\u7531\u65f6\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\">\u5f53\u4f60\u60f3\u8981\u76f4\u63a5\u63a7\u5236 Pod \u7684\u8bbf\u95ee\u65b9\u5f0f\u65f6\u3002<\/span><\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><strong><span style=\"color: #060607; font-weight: bold; letter-spacing: 0.5px; line-height: 22.4px;\">\u64cd\u4f5c\u6b65\u9aa4\uff1a<\/span><\/strong><\/span><\/p>\n<ol class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\">\u521b\u5efa\u4e00\u4e2a Service YAML \u6587\u4ef6\uff0c\u4e0d\u8981\u6307\u5b9a<\/span><code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\">clusterIP: None<\/span><\/code><span style=\"font-size: 16px;\">\uff08\u9ed8\u8ba4\u5c31\u662f None\uff09\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\">\u5e94\u7528\u8be5 YAML \u6587\u4ef6\u6765\u521b\u5efa Service\u3002<\/span><\/li>\n<\/ol>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<section style=\"margin-bottom: unset;\">\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"javascript\"><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"><span class=\"code-snippet__attr\">apiVersion<\/span>: v1<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"><span class=\"code-snippet__attr\">kind<\/span>: <span class=\"code-snippet__title\">Service<\/span><\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"><span class=\"code-snippet__attr\">metadata<\/span>:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> <span class=\"code-snippet__attr\">name<\/span>: headless-service<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"><span class=\"code-snippet__attr\">spec<\/span>:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> # \u6ce8\u610f\u8fd9\u91cc\u4e0d\u6307\u5b9a clusterIP<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> <span class=\"code-snippet__attr\">selector<\/span>:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  <span class=\"code-snippet__attr\">app<\/span>: my-app<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> <span class=\"code-snippet__attr\">ports<\/span>:<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\"> - <span class=\"code-snippet__attr\">name<\/span>: http<\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  <span class=\"code-snippet__attr\">port<\/span>: <span class=\"code-snippet__number\">80<\/span><\/span><\/code><code class=\"code-snippet_outer\"><span class=\"code-snippet_outer\">  <span class=\"code-snippet__attr\">targetPort<\/span>: <span class=\"code-snippet__number\">8080<\/span><\/span><\/code><\/pre>\n<\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold;\">\u5b9e\u73b0\u6548\u679c<\/span>\uff1a<\/span><\/p>\n<ul class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\">\u521b\u5efa Service \u540e\uff0cKubernetes \u4f1a\u4e3a\u6bcf\u4e2a\u5339\u914d\u7684 Pod \u521b\u5efa\u4e00\u4e2a <strong><span style=\"font-size: 16px; color: #007aaa;\">DNS \u8bb0\u5f55<\/span><\/strong>\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\">Pod \u53ef\u4ee5\u901a\u8fc7<\/span><strong><code style=\"box-sizing: inherit; overflow: auto; text-align: justify; color: var(--brand-main); background-color: var(--color-brand-8); margin: 0 var(--gap-xs); padding: var(--gap-xs) var(--gap-sm); border-radius: var(--border-radius-xs); white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px; color: #007aaa;\">&lt;pod-name&gt;.headless-service.default.svc.cluster.local<\/span><\/code><\/strong><span style=\"font-size: 16px;\">\u6765\u8bbf\u95ee\u540c\u4e00 Service \u4e0b\u7684\u5176\u4ed6 Pod\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\">\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\uff0c\u76f4\u63a5\u901a\u8fc7 DNS \u89e3\u6790\u5230\u5177\u4f53\u7684 Pod\u3002<\/span><\/li>\n<\/ul>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<h3 style=\"box-sizing: inherit; margin-block: 0.67em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; letter-spacing: 0.5px; text-align: start;\"><strong>Headless Service \u4f18\u7f3a\u70b9\uff1a<\/strong><\/h3>\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold;\">\u4f18\u70b9<\/span>\uff1a<\/span><\/p>\n<ol class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u76f4\u63a5\u8bbf\u95ee<\/span>\uff1a\u5141\u8bb8\u76f4\u63a5\u901a\u8fc7Pod\u7684\u4e3b\u673a\u540d\u8bbf\u95ee\uff0c\u65e0\u9700\u901a\u8fc7\u8d1f\u8f7d\u5747\u8861\u5668\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u7b80\u5355\u6027<\/span>\uff1a\u4e0d\u9700\u8981Kubernetes\u8fdb\u884c\u6d41\u91cf\u7ba1\u7406\u548c\u8d1f\u8f7d\u5747\u8861\uff0c\u7b80\u5316\u4e86\u7f51\u7edc\u67b6\u6784\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u9002\u7528\u4e8e\u65e0\u72b6\u6001\u670d\u52a1<\/span>\uff1a\u5bf9\u4e8e\u4e0d\u9700\u8981\u8d1f\u8f7d\u5747\u8861\u7684\u65e0\u72b6\u6001\u670d\u52a1\uff0cHeadless Service\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u9009\u62e9\u3002<\/span><\/li>\n<\/ol>\n<p style=\"box-sizing: inherit; overflow: auto hidden; margin-block-end: 1em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px; text-align: start; white-space-collapse: preserve !important; word-break: break-word !important;\"><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u7f3a\u70b9<\/span>\uff1a<\/span><\/p>\n<ol class=\"list-paddingleft-1\" style=\"box-sizing: inherit; margin-block-start: 1em; padding-inline-start: 2em; color: #060607; font-family: -apple-system, blinkmacsystemfont, 'Helvetica Neue', helvetica, 'segoe ui', arial, roboto, 'PingFang SC', miui, 'Hiragino Sans GB', 'Microsoft Yahei', sans-serif; font-size: 14px; letter-spacing: 0.5px;\">\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u6ca1\u6709\u8d1f\u8f7d\u5747\u8861<\/span>\uff1a\u4e0d\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\uff0c\u53ef\u80fd\u5bfc\u81f4\u67d0\u4e9bPod\u8fc7\u8f7d\u800c\u5176\u4ed6Pod\u7a7a\u95f2\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u7ba1\u7406\u590d\u6742\u6027<\/span>\uff1a\u9700\u8981\u624b\u52a8\u7ba1\u7406Pod\u7684\u8bbf\u95ee\u548c\u8d1f\u8f7d\u5206\u914d\uff0c\u589e\u52a0\u4e86\u8fd0\u7ef4\u7684\u590d\u6742\u6027\u3002<\/span><\/li>\n<li><span style=\"font-size: 16px;\"><span style=\"box-sizing: inherit; font-weight: bold; font-size: 16px;\">\u6269\u5c55\u6027\u95ee\u9898<\/span>\uff1a\u5f53\u670d\u52a1\u9700\u8981\u6c34\u5e73\u6269\u5c55\u65f6\uff0c\u624b\u52a8\u7ba1\u7406Pod\u7684\u8bbf\u95ee\u53ef\u80fd\u4f1a\u53d8\u5f97\u4e0d\u5207\u5b9e\u9645\u3002<\/span><\/li>\n<\/ol>\n<\/section>\n<section style=\"margin-bottom: unset;\"><\/section>\n<\/section>\n<section style=\"margin-bottom: unset;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" style=\"width: 100%; display: block; vertical-align: bottom; transform: rotateZ(0deg); -webkit-transform: rotateZ(0deg); -moz-transform: rotateZ(0deg); -ms-transform: rotateZ(0deg); -o-transform: rotateZ(0deg);\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223645588.gif\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-ratio=\"0.2\" data-w=\"600\" data-width=\"100%\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"width: 100%; display: block; vertical-align: bottom; transform: rotateZ(0deg); -webkit-transform: rotateZ(0deg); -moz-transform: rotateZ(0deg); -ms-transform: rotateZ(0deg); -o-transform: rotateZ(0deg);\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223645588.gif\" data-ratio=\"0.2\" data-w=\"600\" data-width=\"100%\" \/><\/noscript><\/p>\n<\/section>\n<section style=\"margin-bottom: unset;\">\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223654663.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" data-galleryid=\"\" data-imgfileid=\"100000133\" data-ratio=\"0.3425925925925926\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223654663.png\" data-galleryid=\"\" data-imgfileid=\"100000133\" data-ratio=\"0.3425925925925926\" data-s=\"300,640\" data-type=\"png\" data-w=\"1080\" \/><\/noscript><\/p>\n<\/section>\n<p style=\"display: none;\">\n<blockquote><p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7: \u8fd0\u7ef4\u4eba\u751f\u6d3b\u6307\u5357<\/p><\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>Service\u662f\u4ec0\u4e48? \u80cc\u666f\uff1a\u6bcf\u4e2aPod\u5177\u6709IP\u5730\u5740\uff0c\u5f53\u4f7f\u7528Deployment\u63a7\u5236\u5668\u65f6\uff0cPod\u7684IP\u5730\u5740\u5f80\u5f80\u52a8\u6001\u53d8\u5316\u3002 \u89e3\u51b3\u65b9\u6cd5 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":6055,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[32],"tags":[],"class_list":["post-6108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-k8s"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223532614-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223545119.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223532614-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223532614-1024x436.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223545119.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223532614-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223532614-1024x436.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223532614.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223545119.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223545119.png","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223551511.png","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223551511.png","id":"image3"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223558674.png","id":"image4"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223558674.png","id":"image5"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223605293.png","id":"image6"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223605293.png","id":"image7"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223610414.png","id":"image8"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223610414.png","id":"image9"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223618451.png","id":"image10"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223618451.png","id":"image11"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223625704.png","id":"image12"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223625704.png","id":"image13"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223633200.png","id":"image14"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223633200.png","id":"image15"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223645588.gif","id":"image16"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223645588.gif","id":"image17"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223654663.png","id":"image18"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/08\/20240801223654663.png","id":"image19"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"K8S","post_date":"2024-08-01","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":852,"next_post_id":null,"next_post_title":null,"previous_post_id":6068,"previous_post_title":"K8s\u5355\u673a\u67b6\u6784\u90e8\u7f72","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6108"}],"version-history":[{"count":2,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6108\/revisions"}],"predecessor-version":[{"id":6420,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6108\/revisions\/6420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/6055"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}