{"id":1131,"date":"2022-02-14T17:25:28","date_gmt":"2022-02-14T09:25:28","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1131"},"modified":"2023-06-09T09:34:21","modified_gmt":"2023-06-09T01:34:21","slug":"k-d-g-x","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2022\/02\/k-d-g-x\/","title":{"rendered":"K8s Service Endpoint Pod\u7684\u5173\u7cfb"},"content":{"rendered":"
Service<\/strong>\u53ea\u662f\u4e00\u4e2a\u62bd\u8c61\u6982\u5ff5\uff0c\u5728\u903b\u8f91\u4e0a\u5c06\u4e00\u7ec4\u529f\u80fd\u76f8\u540c\u7684pod\u7ed9\u62bd\u8c61\u51fa\u6765\u4e00\u4e2a\u7edf\u4e00\u5165\u53e3\u3002\u53ef\u4ee5\u5c06\u4ed6\u7b80\u5355\u7406\u89e3\u4e3a\u505a\u4e86\u4e00\u4e2a\u670d\u52a1\u7684\u8d1f\u8f7d\u5747\u8861\u3002\u6211\u4eec\u77e5\u9053pod\u5728\u91cd\u65b0\u90e8\u7f72\u4e4b\u540eip\u4f1a\u6539\u53d8\uff0c\u6240\u4ee5\u4e00\u822c\u4f1a\u901a\u8fc7service\u6765\u8bbf\u95eepod\u3002core-dns\u4f1a\u7ed9service\u5206\u914d\u4e00\u4e2a\u5185\u90e8\u7684\u865a\u62dfip\uff08\u8be5IP\u4e0d\u662fnode\u8282\u70b9\u4e0a\u7684\u865a\u62dfip\u800c\u662fk8s\u96c6\u7fa4\u5185\u7684\u865a\u62dfip\uff09k8s\u5185\u90e8\u670d\u52a1\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2aip\u6216\u8005\u662fserviceName\u6765\u8bbf\u95ee\u5230pod\u7684\u670d\u52a1\u3002<\/p>\n ClusterIP\uff1a<\/strong>\u4e5f\u662f\u9ed8\u8ba4\u65b9\u5f0f\u3002Service\u4f1a\u5206\u914d\u4e00\u4e2a\u96c6\u7fa4\u5185\u90e8\u7684\u56fa\u5b9a\u865a\u62dfIP\uff0c\u5b9e\u73b0\u96c6\u7fa4\u5185\u901a\u8fc7\u8be5IP\u6765\u5bf9POD\u8fdb\u884c\u8bbf\u95ee\u3002\u8fd9\u4e2a\u53c8\u6709\u4e24\u7c7b\uff0c\u4e0a\u9762\u8bf4\u5230\u7684\u6700\u666e\u901a\u7684Service\uff0cClusterIP\u8fd8\u6709\u4e00\u79cd\u662fHeadless Service\uff0c\u8fd9\u79cd\u5f62\u5f0f\u4e0d\u4f1a\u5206\u914dIP\u4e5f\u4e0d\u4f1a\u901a\u8fc7kube-proxy\u505a\u53cd\u5411\u4ee3\u7406\u6216\u8005\u8d1f\u8f7d\u5747\u8861\uff0c\u800c\u662f\u901a\u8fc7DNS\u63d0\u4f9b\u7a33\u5b9a\u7684\u7f51\u7edcID\u6765\u8bbf\u95ee\uff0cDNS\u4f1a\u5c06headless service\u7684\u540e\u7aef\u76f4\u63a5\u89e3\u6790\u4e3aPOD\u7684IP\u5217\u8868\uff0c\u8fd9\u79cd\u4e3b\u8981\u662f\u5171StatefulSet\u7c7b\u578b\u4f7f\u7528\u3002 Endpoints <\/strong> \u4e5f\u662fk8s\u7684\u4e00\u4e2a\u8d44\u6e90\u5bf9\u8c61\uff0c\u5728\u521b\u5efaService\u7684\u65f6\u5019\u5982\u679c\u6211\u4eec\u8bbe\u7f6e\u4e86\u901a\u8fc7selector <\/strong> \u6807\u7b7e\u5173\u8054\u76f8\u5173\u7684pod\uff0c\u90a3\u4e48Endpoint Controller\u5c31\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u4e0eService\u540c\u540d\u7684Endpoints<\/strong>\u3002\u5b58\u50a8\u5728etcd\u4e2d\uff0c\u7528\u6765\u8bb0\u5f55\u4e00\u4e2aservice\u5bf9\u5e94\u7684\u6240\u6709pod\u7684\u8bbf\u95ee\u5730\u5740\u3002<\/p>\n service\u914d\u7f6eselector\uff0cendpoint controller\u624d\u4f1a\u81ea\u52a8\u521b\u5efa\u5bf9\u5e94\u7684endpoint\u5bf9\u8c61\uff1b\u5426\u5219\u4e0d\u4f1a\u751f\u6210endpoint\u5bf9\u8c61\u3002<\/em><\/p>\n Endpoint Controller<\/strong><\/p>\n endpoint controller\u662fk8s\u96c6\u7fa4\u63a7\u5236\u5668\u7684\u5176\u4e2d\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u5176\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n \u56fe\u7247\u6765\u6e90catoop<\/a><\/p>\n <\/p>\n \u81ea\u52a8\u5173\u8054\u4f53\u7cfb\u5185 Pod \u670d\u52a1\uff08\u4e0b\u56fe\uff09\uff1a<\/p>\n <\/p>\n \u624b\u5de5\u7ef4\u62a4\u4f53\u7cfb\u5916\u7684\u5916\u90e8\u670d\u52a1\uff08\u4e0b\u56fe\uff09\uff1a<\/p>\n <\/p>\nService \u5e38\u7528\u7c7b\u578b\uff1a<\/h3>\n
\nNodePort\uff1a<\/strong>\u8fd9\u79cd\u7c7b\u578b\u7684Service\u662f\u9664\u4e86\u4f7f\u7528ClusterIP\u7684\u529f\u80fd\u5916\u8fd8\u4f1a\u6620\u5c04\u4e00\u4e2a\u5bbf\u4e3b\u673a\u968f\u673a\u7aef\u53e3\u5230service\u4e0a\uff0c\u8fd9\u6837\u96c6\u7fa4\u5916\u90e8\u53ef\u4ee5\u901a\u8fc7\u5bbf\u4e3b\u673aIP+\u968f\u673a\u7aef\u53e3\u6765\u8bbf\u95ee\u3002\u8fd9\u6837\u5f97\u4fdd\u8bc1\u6bcf\u4e00\u4e2anode\u8282\u70b9\u7684\u8be5\u7aef\u53e3\u90fd\u53ef\u7528\u624d\u884c\uff0c\u76f4\u63a5\u4f7f\u7528\u4efb\u610fnode\u8282\u70b9\u7684ip+\u7aef\u53e3\u5c31\u80fd\u76f4\u63a5\u8bbf\u95eepod\u3002
\nHostPort\uff1a<\/strong> \u4ed6\u8fd9\u4e2a\u548cnodeport\u7684\u533a\u522b\u662f\uff0c\u53ea\u5728\u67d0\u4e00\u4e2anode\u8282\u70b9\u6253\u5f00\u7aef\u53e3\u3002
\nLoadBalancer\uff1a<\/strong>\u548cnodePort\u7c7b\u4f3c\uff0c\u4e0d\u8fc7\u9664\u4e86\u4f7f\u7528ClusterIP\u548cNodePort\u4e4b\u5916\u8fd8\u4f1a\u5411\u4f7f\u7528\u7684\u516c\u6709\u4e91\u7533\u8bf7\u4e00\u4e2a\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u4ece\u800c\u5b9e\u73b0\u96c6\u7fa4\u5916\u90e8\u901a\u8fc7LB\u6765\u8bbf\u95ee\u670d\u52a1\u3002\u8fd9\u4e2a\u4e3b\u8981\u662f\u4f9d\u6258\u4e91lb\u3002
\nExternalName\uff1a<\/strong>\u662fService\u7684\u4e00\u79cd\u7279\u4f8b\uff0c\u6b64\u6a21\u5f0f\u4e3b\u8981\u9762\u5bf9\u8fd0\u884c\u5728\u96c6\u7fa4\u5916\u90e8\u7684\u670d\u52a1\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u5c06\u5916\u90e8\u670d\u52a1\u6620\u5c04\u5230k8s\u96c6\u7fa4\uff0c\u5177\u5907k8s\u5185\u670d\u52a1\u7684\u4e00\u4e9b\u7279\u6027\u3002<\/p>\n
\n2\u3001\u4ec0\u4e48\u662fendpoint<\/h2>\n
\n
\n
\n3\u3001Service\u3001Endpoint \u548c Pod \u7684\u5173\u7cfb<\/h2>\n
4\u3001\u5982\u4f55\u5b9e\u73b0\u7684<\/h2>\n
kubernetes\u6838\u5fc3\u7ec4\u4ef6kube-proxy<\/a><\/h1>\n