{"id":1020,"date":"2021-04-10T15:42:49","date_gmt":"2021-04-10T07:42:49","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1020"},"modified":"2023-04-07T10:02:15","modified_gmt":"2023-04-07T02:02:15","slug":"graphical-kubernetes-network-2","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2021\/04\/graphical-kubernetes-network-2\/","title":{"rendered":"\u56fe\u89e3Kubernetes\u7f51\u7edc\uff08\u4e8c\uff09"},"content":{"rendered":"
\u3010\u7f16\u8005\u7684\u8bdd\u3011\u672c\u6587\u662fKubernetes\u7f51\u7edc\u7cfb\u5217\u7684\u7b2c\u4e8c\u90e8\u5206\uff0c\u8be6\u7ec6\u9610\u8ff0\u4e86Overlay\u7f51\u7edc\u5728Kubernetes\u4e2d\u7684\u5de5\u4f5c\u6a21\u5f0f\uff0c\u5e76\u6307\u51faOverlay\u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u53ea\u6709\u5f53\u6211\u4eec\u77e5\u9053\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528Overlay\u6a21\u5f0f\u65f6\u624d\u4f7f\u7528\u5b83\u3002<\/p>\n
\u8fd9\u662fKubernetes\u7f51\u7edc\u7cfb\u5217\u7684\u7b2c\u4e8c\u90e8\u5206\u3002\u5982\u679c\u4f60\u8fd8\u672a\u9605\u8fc7\u8bfb\u7b2c\u4e00\u90e8\u5206<\/a>\uff0c\u5efa\u8bae\u4f60\u5148\u8bfb\u4e00\u4e0b\u3002<\/em><\/p>\n \u8fd9\u7bc7\u6587\u7ae0\u7684\u524d\u4e00\u90e8\u5206<\/a>\uff0c\u6211\u4eec\u6f2b\u8c08\u4e86Kubernetes\u7684\u7f51\u7edc\u6a21\u578b\u3002\u6211\u4eec\u89c2\u5bdf\u4e86\u6570\u636e\u5305\u662f\u5982\u4f55\u5728\u540c\u4e00\u8282\u70b9\u4e0a\u7684pod \u95f4\u548c\u8de8\u8282\u70b9\u7684 pod \u95f4\u6d41\u52a8\u7684\u3002\u6211\u4eec\u4e5f\u6ce8\u610f\u5230\u4e86Linux\u7f51\u6865\u548c\u8def\u7531\u8868\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u6240\u626e\u6f14\u7684\u89d2\u8272\u3002<\/p>\n \u4eca\u5929\u6211\u4eec\u5c06\u8fdb\u4e00\u6b65\u9610\u8ff0\u8fd9\u4e9b\u6982\u5ff5\uff0c\u5e76\u9610\u8ff0Overlay\u7f51\u7edc\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\u6211\u4eec\u4e5f\u5c06\u7406\u89e3Kubernetes\u5343\u53d8\u4e07\u5316\u7684Pod\u662f\u5982\u4f55\u4ece\u8fd0\u884c\u7684\u5e94\u7528\u4e2d\u62bd\u8c61\u51fa\u6765\uff0c\u5e76\u5728\u5e55\u540e\u5904\u7406\u7684\u3002<\/p>\n Overlay\u7f51\u7edc\u4e0d\u662f\u9ed8\u8ba4\u5fc5\u987b\u7684\uff0c\u4f46\u662f\u5b83\u4eec\u5728\u7279\u5b9a\u573a\u666f\u4e0b\u975e\u5e38\u6709\u7528\u3002\u6bd4\u5982\u5f53\u6211\u4eec\u6ca1\u6709\u8db3\u591f\u7684IP\u7a7a\u95f4\uff0c\u6216\u8005\u7f51\u7edc\u65e0\u6cd5\u5904\u7406\u989d\u5916\u8def\u7531\uff0c\u6291\u6216\u5f53\u6211\u4eec\u9700\u8981Overlay\u63d0\u4f9b\u7684\u67d0\u4e9b\u989d\u5916\u7ba1\u7406\u7279\u6027\u3002\u4e00\u4e2a\u5e38\u89c1\u7684\u573a\u666f\u662f\u5f53\u4e91\u63d0\u4f9b\u5546\u7684\u8def\u7531\u8868\u80fd\u5904\u7406\u7684\u8def\u7531\u6570\u662f\u6709\u9650\u5236\u65f6\u3002\u4f8b\u5982\uff0cAWS\u8def\u7531\u8868\u6700\u591a\u652f\u630150\u6761\u8def\u7531\u624d\u4e0d\u81f3\u4e8e\u5f71\u54cd\u7f51\u7edc\u6027\u80fd\u3002\u56e0\u6b64\u5982\u679c\u6211\u4eec\u6709\u8d85\u8fc750\u4e2aKubernetes\u8282\u70b9\uff0cAWS\u8def\u7531\u8868\u5c06\u4e0d\u591f\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528Overlay\u7f51\u7edc\u5c06\u5e2e\u5230\u6211\u4eec\u3002<\/p>\n \u672c\u8d28\u4e0a\u6765\u8bf4\uff0cOverlay\u5c31\u662f\u5728\u8de8\u8282\u70b9\u7684\u672c\u5730\u7f51\u7edc\u4e0a\u7684\u5305\u4e2d\u518d\u5c01\u88c5\u4e00\u5c42\u5305\u3002\u4f60\u53ef\u80fd\u4e0d\u60f3\u4f7f\u7528Overlay\u7f51\u7edc\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5e26\u6765\u7531\u5c01\u88c5\u548c\u89e3\u5c01\u6240\u6709\u62a5\u6587\u5f15\u8d77\u7684\u65f6\u5ef6\u548c\u590d\u6742\u5ea6\u5f00\u9500\u3002\u901a\u5e38\u8fd9\u662f\u4e0d\u5fc5\u8981\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u5e94\u5f53\u5728\u77e5\u9053\u4e3a\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u5b83\u65f6\u624d\u4f7f\u7528\u5b83\u3002<\/p>\n \u4e3a\u4e86\u7406\u89e3Overlay\u7f51\u7edc\u4e2d\u6d41\u91cf\u7684\u6d41\u5411\uff0c\u6211\u4eec\u62ffFlannel<\/a>\u505a\u4f8b\u5b50\uff0c\u5b83\u662fCoreOS \u7684\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee\u3002<\/p>\n <\/p>\n Kubernetes Node with route table\uff08cross node pod-to-pop Traffic flow with flannel overlay network\uff09<\/em><\/p>\n \u8fd9\u91cc\u6211\u4eec\u6ce8\u610f\u5230\u5b83\u548c\u4e4b\u524d\u6211\u4eec\u770b\u5230\u7684\u8bbe\u65bd\u662f\u4e00\u6837\u7684\uff0c\u53ea\u662f\u5728root netns\u4e2d\u65b0\u589e\u4e86\u4e00\u4e2a\u865a\u62df\u7684\u4ee5\u592a\u7f51\u8bbe\u5907\uff0c\u79f0\u4e3aflannel0\u3002\u5b83\u662f\u865a\u62df\u6269\u5c55\u7f51\u7edcVirtual Extensible LAN\uff08VXLAN\uff09\u7684\u4e00\u79cd\u5b9e\u73b0\uff0c\u4f46\u662f\u5728Linux\u4e0a\uff0c\u5b83\u53ea\u662f\u53e6\u4e00\u4e2a\u7f51\u7edc\u63a5\u53e3\u3002<\/p>\n \u4ece 1\u3001\u5b83\u7531 2\u3001\u7136\u540e\u88ab\u4f20\u5230 3a\u3001\u7531\u4e8e\u672c\u8282\u70b9\u4e0a\u6ca1\u6709Pod\u62e5\u6709 3b\u3001flanneld daemon\u548cKubernetes apiserver\u6216\u8005\u5e95\u5c42\u7684etcd\u901a\u4fe1\uff0c\u5b83\u77e5\u9053\u6240\u6709\u7684Pod IP\uff0c\u5e76\u4e14\u77e5\u9053\u5b83\u4eec\u5728\u54ea\u4e2a\u8282\u70b9\u4e0a\u3002\u56e0\u6b64Flannel\u521b\u5efa\u4e86Pod IP\u548cNode IP\u4e4b\u95f4\u7684\u6620\u5c04\uff08\u5728\u7528\u6237\u7a7a\u95f4\uff09\u3002<\/p>\n <\/p>\n Packet-in-packet encapsulation\uff08notice the packet is encapsulated from 3c to 6b in previous diagram\uff09<\/em><\/p>\n \u5c3d\u7ba1\u8fd9\u4e2a\u6620\u5c04\u53d1\u751f\u5728\u7528\u6237\u7a7a\u95f4\uff0c\u771f\u5b9e\u7684\u5c01\u88c5\u4ee5\u53ca\u6570\u636e\u7684\u6d41\u52a8\u53d1\u751f\u5728\u5185\u6838\u7a7a\u95f4\uff0c\u56e0\u6b64\u4ecd\u7136\u662f\u5f88\u5feb\u7684\u3002<\/p>\n 3c\u3001\u5c01\u88c5\u540e\u7684\u5305\u901a\u8fc7 4\u3001\u5305\u5e26\u7740\u8282\u70b9IP\u4fe1\u606f\u4f5c\u4e3a\u6e90\u548c\u76ee\u7684\u5730\u5740\u79bb\u5f00\u672c\u8282\u70b9\u3002<\/p>\n 5\u3001\u4e91\u63d0\u4f9b\u5546\u7684\u8def\u7531\u8868\u5df2\u7ecf\u77e5\u9053\u4e86\u5982\u4f55\u5728\u8282\u70b9\u95f4\u53d1\u9001\u62a5\u6587\uff0c\u56e0\u6b64\u8be5\u62a5\u6587\u88ab\u53d1\u9001\u5230\u76ee\u6807\u5730\u5740 6a\u3001\u5305\u5230\u8fbenode2\u7684 6b\u3001 \u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u62a5\u6587\u7684\u8def\u5f84\u548c\u6211\u4eec\u4e4b\u524d\u5728Part 1<\/a> \u4e2d\u770b\u5230\u7684\u975eOverlay\u7f51\u7edc\u5c31\u662f\u4e00\u81f4\u7684\u4e86\u3002<\/p>\n 6c\u3001\u7531\u4e8eIP forwarding\u5f00\u542f\u7740\uff0c\u5185\u6838\u6309\u7167\u8def\u7531\u8868\u5c06\u62a5\u6587\u8f6c\u53d1\u7ed9\u4e86 7\u3001\u7f51\u6865\u83b7\u53d6\u5230\u4e86\u5305\uff0c\u53d1\u9001ARP\u8bf7\u6c42\uff0c\u53d1\u73b0\u76ee\u6807IP\u5c5e\u4e8e 8\u3001\u5305\u8de8\u8fc7\u7ba1\u9053\u5bf9\u5230\u8fbe \u8fd9\u5c31\u662fKubernetes\u4e2dOverlay\u7f51\u7edc\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u867d\u7136\u4e0d\u540c\u7684\u5b9e\u73b0\u8fd8\u662f\u4f1a\u6709\u7ec6\u5fae\u7684\u5dee\u522b\u3002\u6709\u4e2a\u5e38\u89c1\u7684\u8bef\u533a\u662f\uff0c\u5f53\u6211\u4eec\u4f7f\u7528Kubernetes\uff0c\u6211\u4eec\u5c31\u4e0d\u5f97\u4e0d\u4f7f\u7528Overlay\u7f51\u8def\u3002\u4e8b\u5b9e\u662f\uff0c\u8fd9\u5b8c\u5168\u4f9d\u8d56\u4e8e\u7279\u5b9a\u573a\u666f\u3002\u56e0\u6b64\u8bf7\u786e\u4fdd\u5728\u786e\u5b9e\u9700\u8981\u7684\u573a\u666f\u4e0b\u624d\u4f7f\u7528\u3002<\/p>\n \u672c\u90e8\u5206\u5230\u6b64\u7ed3\u675f\u3002\u5728\u524d\u4e00\u90e8\u5206<\/a>\u6211\u4eec\u5b66\u4e60\u4e86Kubernetes\u7f51\u7edc\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u73b0\u5728\u6211\u4eec\u77e5\u9053\u4e86Overlay\u7f51\u7edc\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\u5728\u4e0b\u4e00\u90e8\u5206\uff0c\u6211\u4eec\u5c06\u770b\u5230Pod\u521b\u5efa\u548c\u5220\u9664\u8fc7\u7a0b\u4e2d\u7f51\u7edc\u53d8\u5316\u662f\u5982\u4f55\u53d1\u751f\u7684\uff0c\u4ee5\u53ca\u51fa\u7ad9\u548c\u8fdb\u7ad9\u6d41\u91cf\u662f\u5982\u4f55\u6d41\u52a8\u7684\u3002<\/p>\n \u603b\u4f53\u800c\u8a00\u6211\u5bf9\u7f51\u7edc\u6982\u5ff5\u4ecd\u7136\u662f\u4e2a\u65b0\u624b\uff0c\u56e0\u6b64\u6211\u975e\u5e38\u671f\u5f85\u80fd\u5f97\u5230\u5927\u5bb6\u7684\u53cd\u9988\uff0c\u7279\u522b\u662f\u67d0\u4e9b\u4e0d\u6e05\u6670\u6216\u8005\u9519\u8bef\u7684\u5730\u65b9\u3002<\/p>\n \u539f\u6587\u94fe\u63a5\uff1aAn illustrated guide to Kubernetes Networking [Part 2]<\/a> \uff08\u7ffb\u8bd1\uff1a\u6c60\u5251\u950b\uff09<\/strong><\/p>\nOverlay \u7f51\u7edc<\/h3>\n
pod1<\/code>\u5230
pod4<\/code>\uff08\u5728\u4e0d\u540c\u8282\u70b9\uff09\u7684\u6570\u636e\u5305\u7684\u6d41\u5411\u7c7b\u4f3c\u5982\u4e0b\uff1a<\/p>\n
pod1<\/code>\u4e2dnetns\u7684
eth0<\/code>\u7f51\u53e3\u79bb\u5f00\uff0c\u901a\u8fc7
vethxxx<\/code>\u8fdb\u5165root netns\u3002<\/p>\n
cbr0<\/code>\uff0ccbr0\u901a\u8fc7\u53d1\u9001ARP\u8bf7\u6c42\u6765\u627e\u5230\u76ee\u6807\u5730\u5740\u3002<\/p>\n
pod4<\/code>\u7684IP\u5730\u5740\uff0c\u56e0\u6b64\u7f51\u6865\u628a\u6570\u636e\u5305\u53d1\u9001\u7ed9\u4e86
flannel0<\/code>\uff0c\u56e0\u4e3a\u8282\u70b9\u7684\u8def\u7531\u8868\u4e0a
flannel0<\/code>\u88ab\u914d\u6210\u4e86Pod\u7f51\u6bb5\u7684\u76ee\u6807\u5730\u5740\u3002<\/p>\n
flannel0<\/code>\u53d6\u5230\u8fd9\u4e2a\u5305\uff0c\u5e76\u5728\u5176\u4e0a\u518d\u7528\u4e00\u4e2aUDP\u5305\u5c01\u88c5\u8d77\u6765\uff0c\u8be5UDP\u5305\u5934\u90e8\u7684\u6e90\u548c\u76ee\u7684IP\u5206\u522b\u88ab\u6539\u6210\u4e86\u5bf9\u5e94\u8282\u70b9\u7684IP\uff0c\u7136\u540e\u53d1\u9001\u8fd9\u4e2a\u65b0\u5305\u5230\u7279\u5b9a\u7684VXLAN\u7aef\u53e3\uff08\u901a\u5e38\u662f8472\uff09\u3002<\/p>\n
eth0<\/code>\u53d1\u9001\u51fa\u53bb\uff0c\u56e0\u4e3a\u5b83\u6d89\u53ca\u4e86\u8282\u70b9\u95f4\u7684\u8def\u7531\u6d41\u91cf\u3002<\/p>\n
node2<\/code>\u3002<\/p>\n
eth0<\/code>\u7f51\u5361\uff0c\u7531\u4e8e\u76ee\u6807\u7aef\u53e3\u662f\u7279\u5b9a\u7684VXLAN\u7aef\u53e3\uff0c\u5185\u6838\u5c06\u62a5\u6587\u53d1\u9001\u7ed9\u4e86
flannel0<\/code>\u3002<\/p>\n
flannel0<\/code>\u89e3\u5c01\u62a5\u6587\uff0c\u5e76\u5c06\u5176\u53d1\u9001\u5230 root \u547d\u540d\u7a7a\u95f4\u4e0b\u3002<\/p>\n
cbr0<\/code>\u3002<\/p>\n
vethyyy<\/code>\u3002<\/p>\n
pod4<\/code>\u3002<\/p>\n