{"id":142043,"date":"2019-04-19T08:39:38","date_gmt":"2019-04-19T00:39:38","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=142043"},"modified":"2019-04-09T09:41:03","modified_gmt":"2019-04-09T01:41:03","slug":"kubernetes-design-document","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/kubernetes-design-document.html","title":{"rendered":"\u7f51\u7edc\u4ecb\u7ecd\uff1aKubernetes\u8bbe\u8ba1\u6587\u6863"},"content":{"rendered":"
Kubernetes\u4eceDocker\u9ed8\u8ba4\u7684\u7f51\u7edc\u6a21\u578b\u4e2d\u72ec\u7acb\u51fa\u6765\u5f62\u6210\u4e00\u5957\u81ea\u5df1\u7684\u7f51\u7edc\u6a21\u578b\u3002\u8be5\u7f51\u7edc\u6a21\u578b\u7684\u76ee\u6807\u662f\uff1a\u6bcf\u4e00\u4e2apod\u90fd\u62e5\u6709\u4e00\u4e2a\u6241\u5e73\u5316\u5171\u4eab\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u7684IP\uff0c\u901a\u8fc7\u8be5IP\uff0cpod\u5c31\u80fd\u591f\u8de8\u7f51\u7edc\u4e0e\u5176\u5b83\u7269\u7406\u673a\u548c\u5bb9\u5668\u8fdb\u884c\u901a\u4fe1\u3002\u4e00\u4e2apod\u4e00\u4e2aIP\u6a21\u578b\u521b\u5efa\u4e86\u4e00\u4e2a\u5e72\u51c0\u3001\u53cd\u5411\u517c\u5bb9\u7684\u6a21\u578b\uff0c\u5728\u8be5\u6a21\u578b\u4e2d\uff0c\u4ece\u7aef\u53e3\u5206\u914d\u3001\u7f51\u7edc\u3001\u57df\u540d\u89e3\u6790\u3001\u670d\u52a1\u53d1\u73b0\u3001\u8d1f\u8f7d\u5747\u8861\u3001\u5e94\u7528\u914d\u7f6e\u548c\u8fc1\u79fb\u7b49\u89d2\u5ea6\uff0cpod\u90fd\u80fd\u591f\u88ab\u770b\u6210\u865a\u62df\u673a\u6216\u7269\u7406\u673a\u3002<\/p>\n
\u53e6\u4e00\u65b9\u9762\uff0c\u52a8\u6001\u7aef\u53e3\u5206\u914d\u9700\u8981\u4ee5\u4e0b\u65b9\u9762\u7684\u652f\u6301\uff1a<\/p>\n
\r\n\u56fa\u5b9a\u7aef\u53e3\uff08\u4f8b\u5982\uff1a\u7528\u4e8e\u5916\u90e8\u53ef\u8bbf\u95ee\u670d\u52a1\uff09\u548c\u52a8\u6001\u5206\u914d\u7aef\u53e3\uff1b\r\n\u5206\u5272\u96c6\u4e2d\u5206\u914d\u548c\u672c\u5730\u83b7\u53d6\u7684\u52a8\u6001\u7aef\u53e3\uff1b \u4e0d\u8fc7\uff0c\u8fd9\u4e0d\u4f46\u4f7f\u8c03\u5ea6\u590d\u6742\u5316\uff08\u56e0\u4e3a\u7aef\u53e3\u662f\u4e00\u79cd\u7a00\u7f3a\u8d44\u6e90\uff09\uff0c\u800c\u4e14\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u4e5f\u5c06\u53d8\u5f97\u590d\u6742\uff0c\u5177\u4f53\u8868\u73b0\u4e3a\u7aef\u53e3\u51b2\u7a81\u3001\u91cd\u7528\u548c\u8017\u5c3d\uff1b\r\n\u4f7f\u7528\u975e\u6807\u51c6\u65b9\u6cd5\u8fdb\u884c\u57df\u540d\u89e3\u6790\uff08\u4f8b\u5982\uff1aetcd\u800c\u4e0d\u662fDNS\uff09\uff1b\r\n\u5bf9\u4f7f\u7528\u6807\u51c6\u57df\u540d\/\u5730\u5740\u89e3\u6790\u673a\u5236\u7684\u7a0b\u5e8f\uff08\u4f8b\u5982\uff1aweb\u6d4f\u89c8\u5668\uff09\u4f7f\u7528\u4ee3\u7406\u548c\/\u6216\u91cd\u5b9a\u5411\uff1b\r\n\u9664\u4e86\u76d1\u63a7\u548c\u7f13\u5b58\u5b9e\u4f8b\u7684\u975e\u6cd5\u5730\u5740\/\u7aef\u53e3\u53d8\u5316\u5916\uff0c\u8fd8\u8981\u76d1\u63a7\u7528\u6237\u7ec4\u6210\u5458\u53d8\u5316\u4ee5\u53ca\u963b\u6b62\u5bb9\u5668\/pod\u8fc1\u79fb\uff08\u4f8b\u5982\uff1a\u4f7f\u7528CRIU\uff09\u3002\r\nNAT\u5c06\u5730\u5740\u7a7a\u95f4\u5206\u6bb5\u7684\u505a\u6cd5\u5f15\u5165\u4e86\u989d\u5916\u7684\u590d\u6742\u6027\uff0c\u8fd9\u5c06\u5e26\u6765\u8bf8\u5982\u7834\u574f\u81ea\u6ce8\u518c\u673a\u5236\u7b49\u95ee\u9898\u3002\r\n<\/pre>\n\u5728\u4e00\u4e2apod\u4e00\u4e2aIP\u6a21\u578b\u4e2d\uff0c\u4ece\u7f51\u7edc\u89d2\u5ea6\u770b\uff0c\u5728\u4e00\u4e2apod\u4e2d\u7684\u6240\u6709\u7528\u6237\u5bb9\u5668\u90fd\u50cf\u662f\u5728\u540c\u4e00\u53f0\u5bbf\u4e3b\u673a\u4e2d\u90a3\u6837\u3002\u5b83\u4eec\u80fd\u591f\u5728\u672c\u5730\u8bbf\u95ee\u5176\u5b83\u7528\u6237\u5bb9\u5668\u7684\u7aef\u53e3\u3002\u66b4\u9732\u7ed9\u4e3b\u673a\u7f51\u5361\u7684\u7aef\u53e3\u662f\u901a\u8fc7\u666e\u901aDocker\u65b9\u5f0f\u5b9e\u73b0\u7684\u3002\u6240\u6709pod\u4e2d\u7684\u5bb9\u5668\u80fd\u591f\u901a\u8fc7\u4ed6\u4eec\u201c10\u201d\u7f51\u6bb5\uff0810.x.x.x\uff09\u7684IP\u5730\u5740\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n
\u9664\u4e86\u80fd\u591f\u907f\u514d\u4e0a\u8ff0\u52a8\u6001\u7aef\u53e3\u5206\u914d\u5e26\u6765\u7684\u95ee\u9898\uff0c\u8be5\u65b9\u6848\u8fd8\u80fd\u4f7f\u5e94\u7528\u5e73\u6ed1\u5730\u4ece\u975e\u5bb9\u5668\u73af\u5883\uff08\u7269\u7406\u673a\u6216\u865a\u62df\u673a\uff09\u8fc1\u79fb\u5230\u540c\u4e00\u4e2apod\u5185\u7684\u5bb9\u5668\u73af\u5883\u3002\u5728\u540c\u4e00\u53f0\u5bbf\u4e3b\u673a\u4e0a\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u6808\u8fd9\u79cd\u573a\u666f\u5df2\u7ecf\u627e\u5230\u907f\u514d\u7aef\u53e3\u51b2\u7a81\u7684\u65b9\u6cd5\uff08\u4f8b\u5982\uff1a\u901a\u8fc7\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff09\u5e76\u4f7f\u5ba2\u6237\u7aef\u80fd\u591f\u627e\u5230\u8fd9\u4e9b\u7aef\u53e3\u3002<\/p>\n
\u8be5\u65b9\u6848\u786e\u5b9e\u964d\u4f4e\u4e86pod\u4e2d\u5bb9\u5668\u4e4b\u95f4\u7684\u9694\u79bb\u6027\u2014\u2014\u5c3d\u7ba1\u7aef\u53e3\u53ef\u80fd\u5b58\u5728\u51b2\u7a81\u800c\u4e14\u4e5f\u4e0d\u5b58\u5728pod\u5185\u8de8\u5bb9\u5668\u7684\u79c1\u6709\u7aef\u53e3\uff0c\u4f46\u662f\u5bf9\u4e8e\u9700\u8981\u81ea\u5df1\u7684\u7aef\u53e3\u8303\u56f4\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u8fd0\u884c\u5728\u4e0d\u540c\u7684pod\u4e2d\uff0c\u800c\u5bf9\u4e8e\u9700\u8981\u8fdb\u884c\u79c1\u6709\u901a\u4fe1\u7684\u8fdb\u7a0b\u5219\u53ef\u4ee5\u8fd0\u884c\u5728\u540c\u4e00\u4e2a\u5bb9\u5668\u5185\u3002\u53e6\u5916\uff0c\u8be5\u65b9\u6848\u5047\u5b9a\u7684\u524d\u63d0\u6761\u4ef6\u662f\uff1a\u5728\u540c\u4e00\u4e2apod\u4e2d\u7684\u5bb9\u5668\u5171\u4eab\u4e00\u4e9b\u8d44\u6e90\uff08\u4f8b\u5982\uff1a\u78c1\u76d8\u5377\u3001\u5904\u7406\u5668\u3001\u5185\u5b58\u7b49\uff09\uff0c\u56e0\u6b64\u635f\u5931\u90e8\u5206\u9694\u79bb\u6027\u4e5f\u5728\u53ef\u63a5\u53d7\u8303\u56f4\u4e4b\u5185\u3002\u6b64\u5916\uff0c\u5c3d\u7ba1\u7528\u6237\u80fd\u591f\u6307\u5b9a\u4e0d\u540c\u5bb9\u5668\u5f52\u5c5e\u5230\u540c\u4e00\u4e2apod\uff0c\u4f46\u4e00\u822c\u60c5\u51b5\u4e0b\u4e0d\u80fd\u6307\u5b9a\u4e0d\u540cpod\u5f52\u5c5e\u4e8e\u540c\u4e00\u53f0\u4e3b\u673a\u3002<\/p>\n
\u5f53\u4efb\u610f\u4e00\u4e2a\u5bb9\u5668\u8c03\u7528SIOCGIFADDR\uff08\u53d1\u8d77\u4e00\u4e2a\u83b7\u53d6\u7f51\u5361IP\u5730\u5740\u7684\u8bf7\u6c42\uff09\u65f6\uff0c\u5b83\u6240\u83b7\u5f97\u7684IP\u548c\u4e0e\u4e4b\u901a\u4fe1\u7684\u5bb9\u5668\u770b\u5230\u7684IP\u662f\u4e00\u6837\u7684\u2014\u2014\u6bcf\u4e2apod\u90fd\u6709\u4e00\u4e2a\u80fd\u591f\u88ab\u5176\u5b83pod\u8bc6\u522b\u7684IP\u3002\u901a\u8fc7\u65e0\u5dee\u522b\u5730\u5bf9\u5f85\u5bb9\u5668\u548cpdo\u5185\u5916\u90e8\u7684IP\u548c\u7aef\u53e3\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u975eNAT\u7684\u6241\u5e73\u5316\u5730\u5740\u7a7a\u95f4\u3002\u201dip addr show\u201d\u80fd\u591f\u50cf\u9884\u671f\u90a3\u6837\u6b63\u5e38\u5de5\u4f5c\u3002\u8be5\u65b9\u6848\u80fd\u591f\u4f7f\u6240\u6709\u73b0\u6709\u7684\u57df\u540d\u89e3\u6790\/\u670d\u52a1\u53d1\u73b0\u673a\u5236\uff1a\u5305\u62ec\u81ea\u6ce8\u518c\u673a\u5236\u548c\u5206\u914dIP\u5730\u5740\u7684\u5e94\u7528\u7a0b\u5e8f\u5728\u5bb9\u5668\u5916\u80fd\u591f\u6b63\u5e38\u8fd0\u884c\uff08\u6211\u4eec\u5e94\u8be5\u7528etcd\u3001Euraka\uff08\u7528\u4e8eAcme Air\uff09\u6216Consul\u7b49\u8f6f\u4ef6\u6d4b\u8bd5\u8be5\u65b9\u6848\uff09\u3002\u5bf9pod\u4e4b\u95f4\u7684\u7f51\u7edc\u901a\u4fe1\uff0c\u6211\u4eec\u5e94\u8be5\u6301\u4e50\u89c2\u6001\u5ea6\u3002\u5728\u540c\u4e00\u4e2apod\u4e2d\u7684\u5bb9\u5668\u4e4b\u95f4\u66f4\u503e\u5411\u4e8e\u901a\u8fc7\u5185\u5b58\u5377\uff08\u4f8b\u5982\uff1atmpfs\uff09\u6216IPC\uff08\u8fdb\u7a0b\u95f4\u901a\u4fe1\uff09\u7684\u65b9\u5f0f\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n
\u8be5\u6a21\u578b\u4e0e\u6807\u51c6Docker\u6a21\u578b\u4e0d\u540c\u3002\u5728\u8be5\u6a21\u578b\u4e2d\uff0c\u6bcf\u4e2a\u5bb9\u5668\u4f1a\u5f97\u5230\u4e00\u4e2a\u201c172\u201d\u7f51\u6bb5\uff08172.x.x.x\uff09\u7684IP\u5730\u5740\uff0c\u800c\u4e14\u901a\u8fc7SIOCGIFADDR\u4e5f\u53ea\u80fd\u770b\u5230\u4e00\u4e2a\u201c172\u201d\u7f51\u6bb5\uff08172.x.x.x\uff09\u7684IP\u5730\u5740\u3002\u5982\u679c\u8fd9\u4e9b\u5bb9\u5668\u4e0e\u5176\u5b83\u5bb9\u5668\u8fde\u63a5\uff0c\u5bf9\u65b9\u5bb9\u5668\u770b\u5230\u7684IP\u5730\u5740\u4e0e\u8be5\u5bb9\u5668\u81ea\u5df1\u901a\u8fc7SIOCGIFADDR\u8bf7\u6c42\u83b7\u53d6\u7684IP\u5730\u5740\u4e0d\u540c\u3002\u7b80\u5355\u5730\u8bf4\uff0c\u4f60\u6c38\u8fdc\u65e0\u6cd5\u5728\u5bb9\u5668\u4e2d\u6ce8\u518c\u4efb\u4f55\u4e1c\u897f\u6216\u670d\u52a1\uff0c\u56e0\u4e3a\u4e00\u4e2a\u5bb9\u5668\u4e0d\u53ef\u80fd\u901a\u8fc7\u5176\u79c1\u6709IP\u5730\u5740\u88ab\u5916\u754c\u8bbf\u95ee\u5230\u3002<\/p>\n
\u6211\u4eec\u60f3\u5230\u7684\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\u662f\u589e\u52a0\u989d\u5916\u7684\u5730\u5740\u5c42\uff1a\u4ee5pod\u4e3a\u4e2d\u5fc3\u7684\u4e00\u4e2a\u5bb9\u5668\u4e00\u4e2aIP\u6a21\u5f0f\u3002\u6bcf\u4e2a\u5bb9\u5668\u53ea\u62e5\u6709\u4e00\u4e2a\u672c\u5730IP\u5730\u5740\uff0c\u4e14\u53ea\u5728pod\u5185\u53ef\u89c1\u3002\u8fd9\u5c06\u4f7f\u5f97\u5bb9\u5668\u5316\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u66f4\u52a0\u5bb9\u6613\u5730\u4ece\u7269\u7406\/\u865a\u62df\u673a\u8fc1\u79fb\u5230pod\uff0c\u4f46\u5b9e\u73b0\u8d77\u6765\u5f88\u590d\u6742\uff08\u4f8b\u5982\uff1a\u8981\u6c42\u4e3a\u6bcf\u4e2apod\u521b\u5efa\u7f51\u6865\uff0c\u6c34\u5e73\u5206\u5272\/\u865a\u62df\u79c1\u6709\u7684 DNS\uff09\uff0c\u800c\u4e14\u53ef\u4ee5\u9884\u89c1\u7684\u662f\uff0c\u7531\u4e8e\u65b0\u589e\u4e86\u989d\u5916\u7684\u5730\u5740\u8f6c\u6362\u5c42\uff0c\u5c06\u7834\u574f\u73b0\u6709\u7684\u81ea\u6ce8\u518c\u548cIP\u5206\u914d\u673a\u5236\u3002<\/p>\n
\u5f53\u524d\u5b9e\u73b0<\/strong><\/span><\/div>\nGoogle\u8ba1\u7b97\u5f15\u64ce\uff08GCE\uff09\u96c6\u7fa4\u914d\u7f6e\u4e86\u9ad8\u7ea7\u8def\u7531\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u865a\u62df\u673a\u90fd\u6709\u989d\u5916\u7684256\u4e2a\u53ef\u8def\u7531IP\u5730\u5740\u3002\u8fd9\u4e9b\u662f\u9664\u4e86\u5206\u914d\u7ed9\u865a\u62df\u673a\u7684\u901a\u8fc7NAT\u7528\u4e8e\u8bbf\u95ee\u4e92\u8054\u7f51\u7684\u201c\u4e3b\u201dIP\u4e4b\u5916\u7684IP\u3002\u8be5\u5b9e\u73b0\u5728Docker\u5916\u90e8\u521b\u5efa\u4e86\u4e00\u4e2a\u53eb\u505acbr0\u7684\u7f51\u6865\uff08\u4e3a\u4e86\u4e0edocker0\u7f51\u6865\u533a\u522b\u5f00\uff09\uff0c\u8be5\u7f51\u6865\u53ea\u8d1f\u8d23\u5bf9\u4ece\u5bb9\u5668\u5185\u90e8\u6d41\u5411\u5916\u90e8\u7684\u7f51\u7edc\u6d41\u91cf\u8fdb\u884cNAT\u8f6c\u53d1\u3002<\/p>\n
\u76ee\u524d\uff0c\u4ece\u201c\u4e3b\u201dIP\uff08\u5373\u4e92\u8054\u7f51\uff0c\u5982\u679c\u5236\u5b9a\u4e86\u6b63\u786e\u7684\u9632\u706b\u5899\u89c4\u5219\u7684\u8bdd\uff09\u53d1\u5230\u6620\u5c04\u7aef\u53e3\u7684\u6d41\u91cf\u7531Docker\u7684\u7528\u6237\u6a21\u5f0f\u8fdb\u884c\u4ee3\u7406\u8f6c\u53d1\u3002\u672a\u6765\uff0c\u7aef\u53e3\u8f6c\u53d1\u5e94\u8be5\u7531Kubelet\u6216Docker\u901a\u8fc7iptables\u8fdb\u884c\uff1aIssue #15\u3002<\/p>\n
\u542f\u52a8Docker\u65f6\u9644\u52a0\u53c2\u6570\uff1aDOCKER_OPTS=\u201d\u2013bridge cbr0 \u2013iptables=false\u201d\u3002<\/p>\n
\u5e76\u7528SaltStack\u5728\u6bcf\u4e2anode\u4e2d\u521b\u5efa\u4e00\u4e2a\u7f51\u6865\uff0c\u4ee3\u7801\u89c1container_bridge.py\uff1a<\/p>\n
\r\ncbr0:\r\ncontainer_bridge.ensure:\r\n\u2013 cidr: {{ grains[\u2018cbr-cidr\u2019] }}\r\n\u2026\r\ngrains:\r\nroles:\r\n\u2013 kubernetes-pool\r\ncbr-cidr: $MINION_IP_RANGE\r\n<\/pre>\n\u5728GCE\u4e2d\uff0c\u6211\u4eec\u8ba9\u4ee5\u4e0bIP\u5730\u5740\u53ef\u8def\u7531\uff1a<\/p>\n
\r\ngcloud compute routes add \u201c${MINION_NAMES[$i]}\u201d \\\r\n\u2013project \u201c${PROJECT}\u201d \\\r\n\u2013destination-range \u201c${MINION_IP_RANGES[$i]}\u201d \\\r\n\u2013network \u201c${NETWORK}\u201d \\\r\n\u2013next-hop-instance \u201c${MINION_NAMES[$i]}\u201d \\\r\n\u2013next-hop-instance-zone \u201c${ZONE}\u201d &\r\n<\/pre>\n\u4ee5\u4e0a\u4ee3\u7801\u4e2d\u7684MINION_IP_RANGES\u662f\u4ee510.\u5f00\u5934\u768424\u4f4d\u7f51\u7edc\u53f7IP\u5730\u5740\u7a7a\u95f4\uff0810.x.x.x\/24\uff09\u3002<\/p>\n
\u5c3d\u7ba1\u5982\u6b64\uff0cGCE\u672c\u8eab\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e9bIP\u5730\u5740\u7684\u4efb\u4f55\u4fe1\u606f\u3002<\/p>\n
\u8fd9\u4e9bIP\u5730\u5740\u4e0d\u662f\u5916\u90e8\u53ef\u8def\u7531\u7684\uff0c\u56e0\u6b64\uff0c\u90a3\u4e9b\u6709\u4e0e\u5916\u754c\u901a\u4fe1\u9700\u6c42\u7684\u5bb9\u5668\u9700\u8981\u4f7f\u7528\u5bbf\u4e3b\u673a\u7684\u7f51\u7edc\u3002\u5982\u679c\u5916\u90e8\u6d41\u91cf\u8981\u8f6c\u53d1\u7ed9\u865a\u62df\u673a\uff0c\u5b83\u53ea\u4f1a\u88ab\u8f6c\u53d1\u7ed9\u865a\u62df\u673a\u7684\u4e3bIP\uff08\u8be5IP\u4e0d\u4f1a\u88ab\u5206\u914d\u7ed9\u4efb\u4f55\u4e00\u4e2apod\uff09\uff0c\u56e0\u6b64\u6211\u4eec\u4f7f\u7528docker\u7684-p\u6807\u8bb0\u628a\u66b4\u9732\u7684\u7aef\u53e3\u6620\u5c04\u5230\u4e3b\u7f51\u5361\u4e0a\u3002\u8be5\u65b9\u6848\u7684\u5e26\u6765\u7684\u526f\u4f5c\u7528\u662f\u4e0d\u5141\u8bb8\u4e24\u4e2a\u4e0d\u540c\u7684pod\u66b4\u9732\u540c\u4e00\u4e2a\u7aef\u53e3\uff08\u66f4\u591a\u76f8\u5173\u8ba8\u8bba\u89c1Issue #390\uff09\u3002<\/p>\n
\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5bb9\u5668\u7528\u4e8e\u7ba1\u7406pod\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff0c\u8be5\u7f51\u7edc\u5bb9\u5668\u5185\u6709\u4e00\u4e2a\u672c\u5730\u56de\u73af\u8bbe\u5907\u548c\u4e00\u5757\u865a\u62df\u4ee5\u592a\u7f51\u5361\u3002\u6240\u6709\u7684\u7528\u6237\u5bb9\u5668\u4ece\u8be5pod\u7684\u7f51\u7edc\u5bb9\u5668\u90a3\u91cc\u83b7\u53d6\u4ed6\u4eec\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n
Docker\u5728\u5b83\u7684\u201ccontainer\u201d\u7f51\u7edc\u6a21\u5f0f\u4e0b\u4ece\u7f51\u6865\uff08\u6211\u4eec\u4e3a\u6bcf\u4e2a\u8282\u70b9\u4e0a\u521b\u5efa\u4e86\u4e00\u4e2a\u7f51\u6865\uff09\u90a3\u91cc\u5206\u914dIP\u5730\u5740\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n
\r\n \u4f7f\u7528\u6700\u5c0f\u955c\u50cf\u521b\u5efa\u4e00\u4e2a\u666e\u901a\u5bb9\u5668\uff08\u4ece\u7f51\u7edc\u89d2\u5ea6\uff09\u5e76\u8fd0\u884c\u4e00\u6761\u6c38\u8fdc\u963b\u585e\u7684\u547d\u4ee4\u3002\u8fd9\u4e0d\u662f\u4e00\u4e2a\u7528\u6237\u5b9a\u4e49\u7684\u5bb9\u5668\uff0c\u7ed9\u5b83\u4e00\u4e2a\u7279\u522b\u7684\u4f17\u6240\u5468\u77e5\u7684\u540d\u5b57\uff1b\r\n \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff08netns\uff09\u548c\u672c\u5730\u56de\u8def\u8bbe\u5907\uff1b\r\n \u521b\u5efa\u4e00\u5bf9\u65b0\u7684\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u5e76\u5c06\u5b83\u7ed1\u5b9a\u5230\u521a\u521a\u521b\u5efa\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff1b\r\n \u4ecedocker\u7684IP\u5730\u5740\u7a7a\u95f4\u4e2d\u81ea\u52a8\u5206\u914d\u4e00\u4e2aIP\uff1b\r\n<\/pre>\n\u5728\u521b\u5efa\u7528\u6237\u5bb9\u5668\u65f6\u6307\u5b9a\u7f51\u7edc\u5bb9\u5668\u7684\u540d\u5b57\u4f5c\u4e3a\u5b83\u4eec\u7684\u201cnet\u201d\u53c2\u6570\u3002Docker\u4f1a\u627e\u5230\u5728\u7f51\u7edc\u5bb9\u5668\u4e2d\u8fd0\u884c\u7684\u547d\u4ee4\u7684PID\u5e76\u5c06\u5b83\u7ed1\u5b9a\u5230\u8be5PID\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u53bb\u3002<\/p>\n
\u5176\u4ed6\u7f51\u7edc\u5b9e\u73b0\u4f8b\u5b50<\/strong><\/span><\/div>\n\u5176\u4ed6\u7528\u4e8e\u5728GCE\u5916\u90e8\u5b9e\u73b0\u4e00\u4e2apod\u4e00\u4e2aIP\u6a21\u578b\u7684\u65b9\u6848\uff1a<\/p>\n
\r\nOpenVSwitch with GRE\/VxLAN\r\nFlannel\r\n<\/pre>\n\u6311\u6218\u548c\u672a\u6765\u7684\u5de5\u4f5c<\/strong><\/span><\/div>\nDocker API<\/p>\n
\u76ee\u524d\uff0cdocker inspect\u5e76\u4e0d\u5c55\u793a\u5bb9\u5668\u7684\u7f51\u7edc\u914d\u7f6e\u4fe1\u606f\uff0c\u56e0\u4e3a\u5b83\u4eec\u4ece\u53e6\u4e00\u4e2a\u5bb9\u5668\u63d0\u53d6\u8be5\u4fe1\u606f\u3002\u8be5\u4fe1\u606f\u5e94\u8be5\u4ee5\u67d0\u79cd\u65b9\u5f0f\u66b4\u9732\u51fa\u6765\u3002<\/p>\n
\u5916\u90e8IP\u5206\u914d<\/strong><\/span><\/div>\n\u6211\u4eec\u5e0c\u671b\u80fd\u591f\u4eceDocker\u5916\u90e8\u5206\u914dIP\u5730\u5740\uff08Docker issue #6743\uff09\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u4e0d\u5fc5\u9759\u6001\u5730\u5206\u914d\u56fa\u5b9a\u5927\u5c0f\u7684IP\u8303\u56f4\u7ed9\u6bcf\u4e2a\u8282\u70b9\uff0c\u800c\u4e14\u5373\u4f7f\u7f51\u7edc\u5bb9\u5668\u91cd\u542f\u4e5f\u80fd\u4fdd\u6301\u5bb9\u5668IP\u5730\u5740\u56fa\u5b9a\u4e0d\u53d8\uff08Docker issue #2801\uff09\uff0c\u8fd9\u6837\u5c31\u4f7f\u5f97pod\u6613\u4e8e\u8fc1\u79fb\u3002\u76ee\u524d\uff0c\u5982\u679c\u7f51\u7edc\u5bb9\u5668\u6302\u6389\uff0c\u6240\u6709\u7684\u7528\u6237\u5bb9\u5668\u5fc5\u987b\u5173\u95ed\u518d\u91cd\u542f\uff0c\u56e0\u4e3a\u7f51\u7edc\u5bb9\u5668\u91cd\u542f\u540e\u5176\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u4f1a\u53d1\u751f\u53d8\u5316\u800c\u4e14\u4efb\u4f55\u4e00\u4e2a\u968f\u540e\u91cd\u542f\u7684\u7528\u6237\u5bb9\u5668\u4f1a\u52a0\u5165\u65b0\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u8fdb\u800c\u5bfc\u81f4\u65e0\u6cd5\u4e0e\u5bf9\u65b9\u5bb9\u5668\u901a\u4fe1\u3002\u53e6\u5916\uff0cIP\u5730\u5740\u7684\u6539\u53d8\u5c06\u4f1a\u5f15\u53d1DNS\u7f13\u5b58\/\u751f\u5b58\u65f6\u95f4\u95ee\u9898\u3002\u5916\u90e8IP\u5206\u914d\u65b9\u6848\u4f1a\u7b80\u5316DNS\u652f\u6301\uff08\u89c1\u4e0b\u6587\uff09\u3002<\/p>\n
\u57df\u540d\u89e3\u6790\uff0c\u670d\u52a1\u53d1\u73b0\u548c\u8d1f\u8f7d\u5747\u8861<\/strong><\/span><\/div>\n\u9664\u4e86\u5229\u7528\u7b2c\u4e09\u65b9\u7684\u53d1\u73b0\u673a\u5236\u6765\u542f\u7528\u81ea\u6ce8\u518c\u5916\uff0c\u6211\u4eec\u8fd8\u5e0c\u671b\u81ea\u52a8\u5efa\u7acbDDNS\uff08Issue #146\uff09\u3002hostname\u65b9\u6cd5\uff0c$HOSTNAME\u7b49\u5e94\u8be5\u8fd4\u56de\u4e00\u4e2apod\u7684\u540d\u5b57\uff08Issue #298\uff09\uff0cgethostbyname\u65b9\u6cd5\u5e94\u8be5\u8981\u80fd\u591f\u89e3\u6790\u5176\u4ed6pod\u7684\u540d\u5b57\u3002\u6211\u4eec\u53ef\u80fd\u4f1a\u5efa\u7acb\u4e00\u4e2aDNS\u89e3\u6790\u670d\u52a1\u5668\u6765\u505a\u8fd9\u4e9b\u4e8b\u60c5\uff08Docker issue #2267\uff09\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u5fc5\u52a8\u6001\u66f4\u65b0\/etc\/hosts\u6587\u4ef6\u3002<\/p>\n
\u670d\u52a1\u7aef\u70b9\u76ee\u524d\u662f\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u83b7\u53d6\u7684\u3002Docker\u94fe\u63a5\u517c\u5bb9\u53d8\u91cf\u548ckubernetes\u6307\u5b9a\u53d8\u91cf\uff08{NAME}_SERVICE_HOST\u548c{NAME}_SERVICE_BAR\uff09\u90fd\u662f\u652f\u6301\u7684\uff0c\u5e76\u4f1a\u88ab\u89e3\u6790\u6210\u7531\u670d\u52a1\u4ee3\u7406\u6253\u5f00\u7684\u7aef\u53e3\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u5e76\u4e0d\u4f7f\u7528docker\u7279\u4f7f\u6a21\u5f0f\u6765\u94fe\u63a5\u5bb9\u5668\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u9700\u8981\u5e94\u7528\u7a0b\u5e8f\u5728\u914d\u7f6e\u9636\u6bb5\u8bc6\u522b\u6240\u6709\u5ba2\u6237\u7aef\u3002\u867d\u7136\u5982\u4eca\u7684\u670d\u52a1\u90fd\u662f\u7531\u670d\u52a1\u4ee3\u7406\u7ba1\u7406\u7684\uff0c\u4f46\u662f\u8fd9\u662f\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e0d\u5e94\u8be5\u4f9d\u8d56\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u5ba2\u6237\u7aef\u5e94\u8be5\u4f7f\u7528\u670d\u52a1\u5165\u53e3IP\uff08\u4ee5\u4e0a\u73af\u5883\u53d8\u91cf\u4f1a\u88ab\u89e3\u6790\u6210\u8be5IP\uff09\u3002\u7136\u800c\uff0c\u4e00\u4e2a\u6241\u5e73\u5316\u7684\u670d\u52a1\u547d\u540d\u7a7a\u95f4\u65e0\u6cd5\u4f38\u7f29\uff0c\u800c\u4e14\u73af\u5883\u53d8\u91cf\u4e0d\u5141\u8bb8\u52a8\u6001\u66f4\u65b0\uff0c\u8fd9\u4f7f\u5f97\u901a\u8fc7\u5e94\u7528\u9690\u6027\u7684\u987a\u5e8f\u9650\u5236\u8fdb\u884c\u670d\u52a1\u90e8\u7f72\u53d8\u5f97\u590d\u6742\u3002\u6211\u4eec\u6253\u7b97\u5728DNS\u4e2d\u4e3a\u6bcf\u4e2a\u670d\u52a1\u6ce8\u518c\u5165\u53e3IP\uff0c\u5e76\u4e14\u5e0c\u671b\u8fd9\u79cd\u65b9\u5f0f\u80fd\u591f\u6210\u4e3a\u9996\u9009\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n
\u6211\u4eec\u4e5f\u5e0c\u671b\u9002\u5e94\u5176\u5b83\u7684\u8d1f\u8f7d\u5747\u8861\u65b9\u6848\uff08\u4f8b\u5982\uff1aHAProxy\uff09\uff0c\u975e\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\uff08Issue #260\uff09\u548c\u5176\u5b83\u7c7b\u578b\u7684\u5206\u7ec4\uff08\u4f8b\u5982\uff1a\u7ebf\u7a0b\u6c60\u7b49\uff09\u3002\u63d0\u4f9b\u76d1\u6d4b\u5e94\u7528\u5230pod\u5730\u5740\u7684\u6807\u8bb0\u9009\u62e9\u5668\u7684\u80fd\u529b\u4f7f\u6709\u6548\u5730\u76d1\u63a7\u7528\u6237\u7ec4\u6210\u5458\u72b6\u6001\u53d8\u5f97\u53ef\u80fd\uff0c\u8fd9\u4e9b\u76d1\u63a7\u6570\u636e\u5c06\u76f4\u63a5\u88ab\u670d\u52a1\u53d1\u73b0\u673a\u5236\u6d88\u8d39\u6216\u540c\u6b65\u3002\u7528\u4e8e\u76d1\u542c\/\u53d6\u6d88\u76d1\u542c\u4e8b\u4ef6\u7684\u4e8b\u4ef6\u94a9\uff08Issue #140\uff09\u5c06\u4f7f\u4e0a\u8ff0\u76ee\u6807\u66f4\u5bb9\u6613\u5b9e\u73b0\u3002<\/p>\n
\u5916\u90e8\u53ef\u8def\u7531\u6027<\/strong><\/span><\/div>\n\u6211\u4eec\u5e0c\u671b\u8de8\u8282\u70b9\u7684\u5bb9\u5668\u95f4\u7f51\u7edc\u901a\u4fe1\u4f7f\u7528pod IP\u5730\u5740\u3002\u5047\u8bbe\u8282\u70b9A\u7684\u5bb9\u5668IP\u5730\u5740\u7a7a\u95f4\u662f10.244.1.0\/24\uff0c\u8282\u70b9B\u7684\u5bb9\u5668\u7684IP\u5730\u5740\u7a7a\u95f4\u662f10.244.2.0\/24\uff0c\u4e14\u5bb9\u5668A1\u7684\u7684IP\u5730\u5740\u662f10.244.1.1\uff0c\u5bb9\u5668B1\u7684IP\u5730\u5740\u662f10.244.2.1\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5e0c\u671b\u5bb9\u5668A1\u80fd\u591f\u76f4\u63a5\u4e0e\u5bb9\u5668B1\u901a\u4fe1\u800c\u4e0d\u901a\u8fc7NAT\uff0c\u90a3\u4e48\u5bb9\u5668B1\u770b\u5230IP\u5305\u7684\u6e90IP\u5e94\u8be5\u662f10.244.1.1\u800c\u4e0d\u662f\u8282\u70b9A\u7684\u4e3b\u5bbf\u4e3b\u673aIP\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u5e0c\u671b\u5173\u95ed\u7528\u4e8e\u5bb9\u5668\u4e4b\u95f4\uff08\u4ee5\u53ca\u5bb9\u5668\u548c\u865a\u62df\u673a\u4e4b\u95f4\uff09\u901a\u4fe1\u7684NAT\u3002<\/p>\n
\u6211\u4eec\u4e5f\u5e0c\u671b\u4ece\u5916\u90e8\u4e92\u8054\u7f51\u80fd\u591f\u76f4\u63a5\u8def\u7531\u5230pod\u3002\u7136\u800c\uff0c\u6211\u4eec\u8fd8\u65e0\u6cd5\u63d0\u4f9b\u989d\u5916\u7684\u7528\u4e8e\u76f4\u63a5\u8bbf\u95ee\u4e92\u8054\u7f51\u7684\u5bb9\u5668IP\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u4e0d\u5c06\u5916\u90e8IP\u6620\u5c04\u5230\u5bb9\u5668IP\u3002\u6211\u4eec\u901a\u8fc7\u8ba9\u7ec8\u70b9\u4e0d\u662f\u5185\u90e8\u7f51\u7edc\uff08!10.0.0.0\/8\uff09\u7684\u6d41\u91cf\u7ecf\u8fc7\u4e3b\u5bbf\u4e3b\u673aIP\u8d70NAT\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u8fd9\u6837\u4e0e\u56e0\u7279\u7f51\u901a\u4fe1\u65f6\u5c31\u80fd\u901a\u8fc7GCE\u7f51\u7edc\u5b9e\u73b01\uff1a1NAT\u8f6c\u6362\u3002\u7c7b\u4f3c\u5730\uff0c\u4ece\u56e0\u7279\u7f51\u6d41\u5411\u5185\u90e8\u7f51\u7edc\u7684\u6d41\u91cf\u4e5f\u80fd\u591f\u7ecf\u5bbf\u4e3b\u673aIP\u5b9e\u73b0NAT\u8f6c\u6362\/\u4ee3\u7406\u3002<\/p>\n
\u56e0\u6b64\uff0c\u8ba9\u6211\u4eec\u7528\u4e09\u4e2a\u7528\u4f8b\u573a\u666f\u7ed3\u675f\u4e0a\u9762\u7684\u8ba8\u8bba\uff1a<\/p>\n
\u5bb9\u5668->\u5bb9\u5668\u6216\u5bb9\u5668< ->\u865a\u62df\u673a\u3002\u8be5\u573a\u666f\u9700\u8981\u76f4\u63a5\u4f7f\u7528\u4ee510.\u5f00\u5934\u7684\u5730\u5740\uff0810.x.x.x\uff09\uff0c\u5e76\u4e14\u4e0d\u9700\u8981\u7528\u5230NAT\uff1b<\/p>\n
\u5bb9\u5668->\u56e0\u7279\u7f51\u3002\u5bb9\u5668IP\u9700\u8981\u6620\u5c04\u5230\u4e3b\u5bbf\u4e3b\u673aIP\u597d\u8ba9GCE\u77e5\u9053\u5982\u4f55\u5411\u5916\u53d1\u9001\u8fd9\u4e9b\u6d41\u91cf\u3002\u8fd9\u91cc\u5c31\u6709\u4e24\u5c42NAT\uff1a\u5bb9\u5668IP->\u5185\u90e8\u5bbf\u4e3b\u673aIP->\u5916\u90e8\u4e3b\u673aIP\u3002\u7b2c\u4e00\u5c42\u7ed3\u5408IP\u8868\u53d1\u751f\u5728\u5ba2\u6237\u5bb9\u5668\u4e0a\uff0c\u7b2c\u4e8c\u5c42\u5219\u662fGCE\u7f51\u7edc\u7684\u4e00\u90e8\u5206\u3002\u7b2c\u4e00\u5c42\uff08\u5bb9\u5668IP->\u5185\u90e8\u5bbf\u4e3b\u673aIP\uff09\u8fdb\u884c\u4e86\u52a8\u6001\u7aef\u53e3\u5206\u914d\uff0c\u800c\u7b2c\u4e8c\u5c42\u7684\u7aef\u53e3\u6620\u5c04\u662f1\uff1a1\u7684\uff1b<\/p>\n
\u56e0\u7279\u7f51->\u5bb9\u5668\u3002\u8be5\u573a\u666f\u7684\u6d41\u91cf\u5fc5\u987b\u901a\u8fc7\u4e3b\u5bbf\u4e3b\u673aIP\u800c\u4e14\u7406\u60f3\u72b6\u6001\u4e0b\u4e5f\u62e5\u6709\u4e24\u5c42NAT\u3002\u4f46\u662f\uff0c\u76ee\u524d\u7684\u6d41\u91cf\u8def\u5f84\u662f\uff1a\u5916\u90e8\u4e3b\u673aIP -> \u5185\u90e8\u4e3b\u673aIP -> Docker) -> (Docker -> \u5bb9\u5668IP)\uff0c\u5373Docker\u662f\u4e2d\u95f4\u4ee3\u7406\u3002\u4e00\u65e6\uff08issue #15\uff09\u88ab\u89e3\u51b3\uff0c\u90a3\u4e48\u5c31\u5e94\u8be5\u662f\uff1a\u5916\u90e8\u4e3b\u673aIP -> \u5185\u90e8\u4e3b\u673aIP -> \u5bb9\u5668IP\u3002\u4f46\u662f\uff0c\u4e3a\u4e86\u5b9e\u73b0\u540e\u8005\uff0c\u5c31\u5fc5\u987b\u4e3a\u6bcf\u4e2a\u7ba1\u7406\u7684\u7aef\u53e3\u5efa\u7acb\u7aef\u53e3\u8f6c\u53d1\u7684\u9632\u706b\u5899\uff08iptables\uff09\u3002<\/p>\n
\u5982\u679c\u6211\u4eec\u6709\u529e\u6cd5\u8ba9\u5916\u90e8IP\u8def\u7531\u5230\u96c6\u7fa4\u4e2d\u7684pod\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u91c7\u7528\u4e3a\u6bcf\u4e2apod\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bbf\u4e3b\u673a\u7f51\u5361\u522b\u540d\u7684\u65b9\u6848\u3002\u8be5\u65b9\u6848\u80fd\u591f\u6d88\u9664\u4f7f\u7528\u5bbf\u4e3b\u673aIP\u5730\u5740\u5e26\u6765\u7684\u8c03\u5ea6\u9650\u5236\u3002<\/p>\n
IPv6<\/strong><\/span><\/div>\nIPv6\u5c06\u4f1a\u662f\u4e00\u4e2a\u6709\u610f\u601d\u7684\u9009\u9879\uff0c\u4f46\u6211\u4eec\u8fd8\u6ca1\u6cd5\u4f7f\u7528\u5b83\u3002\u652f\u6301IPv6\u5df2\u7ecf\u88ab\u63d0\u5230Docker\u7684\u65e5\u7a0b\u4e0a\u4e86\uff1aDocker issue #2974\uff0cDocker issue #6923\uff0cDocker issue #6975\u3002\u53e6\u5916\uff0c\u4e3b\u6d41\u4e91\u670d\u52a1\u63d0\u4f9b\u5546\uff08\u4f8b\u5982\uff1aAWS EC2\uff0cGCE\uff09\u76ee\u524d\u4e5f\u4e0d\u652f\u6301\u76f4\u63a5\u7ed9\u865a\u62df\u673a\u7ed1\u5b9aIPv6\u5730\u5740\u3002\u5c3d\u7ba1\u5982\u6b64\uff0c\u6211\u4eec\u5c06\u5f88\u9ad8\u5174\u63a5\u53d7\u5728\u7269\u7406\u673a\u4e0a\u8fd0\u884cKubernetes\u7684\u7528\u6237\u63d0\u4ea4\u7684\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
Kubernetes\u4eceDocker\u9ed8\u8ba4\u7684\u7f51\u7edc\u6a21\u578b\u4e2d\u72ec\u7acb\u51fa\u6765\u5f62\u6210\u4e00\u5957\u81ea\u5df1\u7684\u7f51\u7edc\u6a21\u578b\u3002\u8be5\u7f51\u7edc\u6a21\u578b\u7684\u76ee\u6807\u662f\uff1a\u6bcf\u4e00\u4e2ap […]<\/p>\n","protected":false},"author":1479,"featured_media":142113,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-142043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=142043"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142043\/revisions"}],"predecessor-version":[{"id":142119,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142043\/revisions\/142119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/142113"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=142043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=142043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=142043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}