{"id":1127,"date":"2022-02-14T17:24:21","date_gmt":"2022-02-14T09:24:21","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1127"},"modified":"2023-04-07T09:56:00","modified_gmt":"2023-04-07T01:56:00","slug":"kube-proxy-the-core-component-of-kubernetes","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2022\/02\/kube-proxy-the-core-component-of-kubernetes\/","title":{"rendered":"kubernetes\u6838\u5fc3\u7ec4\u4ef6kube-proxy"},"content":{"rendered":"

\u4e00. kube-proxy \u548c service<\/strong> <\/p>\n

kube-proxy\u662fKubernetes\u7684\u6838\u5fc3\u7ec4\u4ef6\uff0c\u90e8\u7f72\u5728\u6bcf\u4e2aNode\u8282\u70b9\u4e0a\uff0c\u5b83\u662f\u5b9e\u73b0Kubernetes Service\u7684\u901a\u4fe1\u4e0e\u8d1f\u8f7d\u5747\u8861\u673a\u5236\u7684\u91cd\u8981\u7ec4\u4ef6; kube-proxy\u8d1f\u8d23\u4e3aPod\u521b\u5efa\u4ee3\u7406\u670d\u52a1\uff0c\u4eceapiserver\u83b7\u53d6\u6240\u6709server\u4fe1\u606f\uff0c\u5e76\u6839\u636eserver\u4fe1\u606f\u521b\u5efa\u4ee3\u7406\u670d\u52a1\uff0c\u5b9e\u73b0server\u5230Pod\u7684\u8bf7\u6c42\u8def\u7531\u548c\u8f6c\u53d1\uff0c\u4ece\u800c\u5b9e\u73b0K8s\u5c42\u7ea7\u7684\u865a\u62df\u8f6c\u53d1\u7f51\u7edc\u3002<\/p>\n

\u5728k8s\u4e2d\uff0c\u63d0\u4f9b\u76f8\u540c\u670d\u52a1\u7684\u4e00\u7ec4pod\u53ef\u4ee5\u62bd\u8c61\u6210\u4e00\u4e2aservice\uff0c\u901a\u8fc7service\u63d0\u4f9b\u7684\u7edf\u4e00\u5165\u53e3\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u6bcf\u4e2aservice\u90fd\u6709\u4e00\u4e2a\u865a\u62dfIP\u5730\u5740\uff08VIP\uff09\u548c\u7aef\u53e3\u53f7\u4f9b\u5ba2\u6237\u7aef\u8bbf\u95ee\u3002kube-proxy\u5b58\u5728\u4e8e\u5404\u4e2anode\u8282\u70b9\u4e0a\uff0c\u4e3b\u8981\u7528\u4e8eService\u529f\u80fd\u7684\u5b9e\u73b0\uff0c\u5177\u4f53\u6765\u8bf4\uff0c\u5c31\u662f\u5b9e\u73b0\u96c6\u7fa4\u5185\u7684\u5ba2\u6237\u7aefpod\u8bbf\u95eeservice\uff0c\u6216\u8005\u662f\u96c6\u7fa4\u5916\u7684\u4e3b\u673a\u901a\u8fc7NodePort\u7b49\u65b9\u5f0f\u8bbf\u95eeservice\u3002\u5728\u5f53\u524d\u7248\u672c\u7684k8s\u4e2d\uff0ckube-proxy\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fiptables\u6a21\u5f0f\uff0c\u901a\u8fc7\u5404\u4e2anode\u8282\u70b9\u4e0a\u7684iptables\u89c4\u5219\u6765\u5b9e\u73b0service\u7684\u8d1f\u8f7d\u5747\u8861\uff0c\u4f46\u662f\u968f\u7740service\u6570\u91cf\u7684\u589e\u5927\uff0ciptables\u6a21\u5f0f\u7531\u4e8e\u7ebf\u6027\u67e5\u627e\u5339\u914d\u3001\u5168\u91cf\u66f4\u65b0\u7b49\u7279\u70b9\uff0c\u5176\u6027\u80fd\u4f1a\u663e\u8457\u4e0b\u964d\u3002\u4ecek8s\u76841.8\u7248\u672c\u5f00\u59cb\uff0ckube-proxy\u5f15\u5165\u4e86IPVS\u6a21\u5f0f\uff0cIPVS\u6a21\u5f0f\u4e0eiptables\u540c\u6837\u57fa\u4e8eNetfilter\uff0c\u4f46\u662f\u91c7\u7528\u7684hash\u8868\uff0c\u56e0\u6b64\u5f53service\u6570\u91cf\u8fbe\u5230\u4e00\u5b9a\u89c4\u6a21\u65f6\uff0chash\u67e5\u8868\u7684\u901f\u5ea6\u4f18\u52bf\u5c31\u4f1a\u663e\u73b0\u51fa\u6765\uff0c\u4ece\u800c\u63d0\u9ad8service\u7684\u670d\u52a1\u6027\u80fd\u3002<\/p>\n

kube-proxy\u8d1f\u8d23\u4e3aService\u63d0\u4f9bcluster\u5185\u90e8\u7684\u670d\u52a1\u53d1\u73b0\u548c\u8d1f\u8f7d\u5747\u8861\uff0c\u5b83\u8fd0\u884c\u5728\u6bcf\u4e2aNode\u8ba1\u7b97\u8282\u70b9\u4e0a\uff0c\u8d1f\u8d23Pod\u7f51\u7edc\u4ee3\u7406, \u5b83\u4f1a\u5b9a\u65f6\u4eceetcd\u670d\u52a1\u83b7\u53d6\u5230service\u4fe1\u606f\u6765\u505a\u76f8\u5e94\u7684\u7b56\u7565\uff0c\u7ef4\u62a4\u7f51\u7edc\u89c4\u5219\u548c\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u5de5\u4f5c\u3002\u5728K8s\u96c6\u7fa4\u4e2d\u5fae\u670d\u52a1\u7684\u8d1f\u8f7d\u5747\u8861\u662f\u7531Kube-proxy\u5b9e\u73b0\u7684\uff0c\u5b83\u662fK8s\u96c6\u7fa4\u5185\u90e8\u7684\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u4e5f\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5728K8s\u7684\u6bcf\u4e2a\u8282\u70b9\u4e0a\u90fd\u6709\u4e00\u4e2a\uff0c\u8fd9\u4e00\u8bbe\u8ba1\u4f53\u73b0\u4e86\u5b83\u7684\u4f38\u7f29\u6027\u4f18\u52bf\uff0c\u9700\u8981\u8bbf\u95ee\u670d\u52a1\u7684\u8282\u70b9\u8d8a\u591a\uff0c\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u80fd\u529b\u7684Kube-proxy\u5c31\u8d8a\u591a\uff0c\u9ad8\u53ef\u7528\u8282\u70b9\u4e5f\u968f\u4e4b\u589e\u591a\u3002<\/p>\n

service\u662f\u4e00\u7ec4pod\u7684\u670d\u52a1\u62bd\u8c61\uff0c\u76f8\u5f53\u4e8e\u4e00\u7ec4pod\u7684LB\uff0c\u8d1f\u8d23\u5c06\u8bf7\u6c42\u5206\u53d1\u7ed9\u5bf9\u5e94\u7684pod\u3002service\u4f1a\u4e3a\u8fd9\u4e2aLB\u63d0\u4f9b\u4e00\u4e2aIP\uff0c\u4e00\u822c\u79f0\u4e3acluster IP\u3002kube-proxy\u7684\u4f5c\u7528\u4e3b\u8981\u662f\u8d1f\u8d23service\u7684\u5b9e\u73b0\uff0c\u5177\u4f53\u6765\u8bf4\uff0c\u5c31\u662f\u5b9e\u73b0\u4e86\u5185\u90e8\u4ecepod\u5230service\u548c\u5916\u90e8\u7684\u4ecenode port\u5411service\u7684\u8bbf\u95ee\u3002<\/p>\n

\u7b80\u5355\u6765\u8bf4: <\/p>\n