{"id":379,"date":"2020-05-26T23:47:23","date_gmt":"2020-05-26T15:47:23","guid":{"rendered":"https:\/\/www.funnymuddy.com\/?p=379"},"modified":"2020-06-11T20:20:14","modified_gmt":"2020-06-11T12:20:14","slug":"kubernetes-network","status":"publish","type":"post","link":"https:\/\/www.funnymuddy.com\/?p=379","title":{"rendered":"kubernetes network"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Pod\u5185containers<\/h2>\n\n\n\n<p><a href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-overview\/#how-pods-manage-multiple-containers\" target=\"_blank\" rel=\"noreferrer noopener\">Pod\u5185\u6709\u4e00\u4e2a\u6216\u8005\u591a\u4e2acontainer<\/a>\uff0c\u5171\u4eabnetworking(IP\/Port)\u548cstorage(\u6bcf\u4e2aPod\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u6216\u591a\u4e2aPod\u5185containers\u5171\u4eab\u7684storage volumes)\u3002<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-6.png\" alt=\"\" class=\"wp-image-386\" width=\"426\" height=\"456\" srcset=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-6.png 852w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-6-280x300.png 280w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-6-768x822.png 768w\" sizes=\"auto, (max-width: 426px) 100vw, 426px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pod-to-pod<\/h2>\n\n\n\n<p>Kubernetes\u89c4\u5b9aPod\/Node\u901a\u8baf\u5fc5\u987b\u6ee1\u8db3\u4ee5\u4e0b\u8981\u6c42\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pods on a node can communicate with all pods on all nodes without NAT<\/li><li>Agents on a node (e.g. system daemons, kubelet) can communicate with all pods on that node<\/li><li>Pods in the host network of a node can communicate with all pods on all nodes without NAT<\/li><\/ul>\n\n\n\n<p>Kubernetes\/Containers\u4f9d\u8d56\u4e8eLinux namespace\u6765\u9694\u79bb\u7cfb\u7edf\u8d44\u6e90\uff1aprocess, networking, mount, user etc\u3002\u6bcf\u4e2aPod\u6709\u81ea\u5df1\u7684network namespace\uff0cPod\u548cPod\u5916\u7684\u8bbe\u5907\u4ea4\u4e92\u9700\u8981\u901a\u8fc7veth paires\uff08\u865a\u62df\u7f51\u5361\u5bf9\uff09\u6765\u5b9e\u73b0\uff0c\u5206\u522b\u8fde\u63a5\u5230Pod\u548cHost\u7684network namespace\uff0c\u90a3\u4e48Pod\u662f\u600e\u4e48\u548c\u5916\u754c\u5c24\u5176\u662f\u4e0d\u540cNode\u7684Pod\u4ea4\u4e92\u7684\u5462\uff0cKubernetes\u6ca1\u6709\u81ea\u5df1\u5b9e\u73b0\u6216\u8005\u9650\u5b9a\u67d0\u79cd\u65b9\u6848\uff0c\u6240\u6709\u7684\u5de5\u4f5c\u90fd\u4ea4\u7ed9CNI plugin\uff0c\u6bd4\u5982Flannel\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/www.openvswitch.org\/\" target=\"_blank\">Open vSwtich<\/a>\u7b49\u3002CNI plugin\u4f1a\u521b\u5efa\u865a\u62df\u7f51\u5361\u5bf9\uff0c\u5e76\u7ed9Pod\u7f51\u7edc\u7a7a\u95f4\u5206\u914d\u4e00\u4e2aIP\u3002CNI plugin\u4f1a\u8fd0\u884c\u5728\u6bcf\u4e2anode\u4e0a\uff0c\u8def\u5f84\u662f\/opt\/cni\/bin\uff0c\u914d\u7f6e\u6587\u4ef6\u5728\/etc\/cni\/net.d\u3002<\/p>\n\n\n\n<p>\u5f52\u7eb3\u8d77\u6765\uff0cCNI plugins\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u4e09\u79cd\u65b9\u5f0f\u5b9e\u73b0Pod\u95f4\u7684\u7f51\u7edc\u901a\u4fe1\uff0c\u53ef\u53c2\u8003<a href=\"https:\/\/superuser.openstack.org\/articles\/review-of-pod-to-pod-communications-in-kubernetes\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Layer 2 solution (switching)<\/li><li>Layer 3 solution (routing)<\/li><li>Overlay solution<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-7-1024x525.png\" alt=\"\" class=\"wp-image-395\" width=\"512\" height=\"263\" srcset=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-7-1024x525.png 1024w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-7-300x154.png 300w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-7-768x394.png 768w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-7.png 1186w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-8-1024x525.png\" alt=\"\" class=\"wp-image-396\" width=\"512\" height=\"263\" srcset=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-8-1024x525.png 1024w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-8-300x154.png 300w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-8-768x394.png 768w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-8.png 1186w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-9-1024x525.png\" alt=\"\" class=\"wp-image-397\" width=\"512\" height=\"263\" srcset=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-9-1024x525.png 1024w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-9-300x154.png 300w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-9-768x394.png 768w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-9.png 1186w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">service<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">ClusterIP<\/h4>\n\n\n\n<p>\u4e00\u4e2a\u5e94\u7528\u90e8\u7f72\u5728pod\uff0c\u5f53\u7136\u53ef\u4ee5\u88ab\u5176\u4ed6pod\u8bbf\u95ee\uff0c\u53ef\u662fpod\u4e0d\u662f\u5e38\u6001\u7684\u5b58\u5728\uff0c\u4f1a\u88ab\u9500\u6bc1\u521b\u5efa\uff0c\u56e0\u6b64\u67d0\u4e2a\u5e94\u7528\u7684IP\u662f\u4f1a\u53d8\u5316\u7684\uff0c\u8fd9\u5bf9\u4e8e\u5e94\u7528\u4e92\u76f8\u8c03\u7528\u6765\u8bf4\u975e\u5e38\u4e0d\u53cb\u597d\u3002\u90a3\u4e48\u600e\u4e48\u89e3\u51b3\u5462\uff1f\u7b54\u6848\u5c31\u662fservice\u3002\u4e00\u4e2aservice\u4f1a\u6709\u4e00\u4e2aClusterIP (Virtual IP)\uff0c\u5bf9\u5e94\u7740\u4e00\u4e2a\u6216\u8005\u591a\u4e2apod\uff0cetcd\u4fdd\u5b58\u8fd9\u6837\u4e00\u4e2a\u6620\u5c04\u8868\u3002\u5f53\u67d0\u4e2aservice\u7684pod\u521b\u5efa\u540e\uff0ckubelet\u4f1a\u628apod IP\u4e0a\u4f20\u5230etcd\u3002\u6bcf\u4e2anode\u4e0a\u7684kube-proxy\u4f1a\u76d1\u542cservice\u4fe1\u606f\uff0c\u5e76\u5728\u5176\u6240\u5728\u7684node\u4e0a\u914d\u7f6eiptables\u89c4\u5219\uff0c\u5f53\u6709\u6d41\u5165\u7684\u8bbf\u95ee\uff08\u8bbf\u95eeClusterIP\uff09\u65f6\uff0c\u4f1a\u5c06\u6d41\u91cf\u5bfc\u5411\u76f8\u5e94\u7684pod\uff0c\u9ed8\u8ba4\u89c4\u5219\u662fround-robin\u3002<\/p>\n\n\n\n<p><strong>kube-proxy<\/strong>&nbsp;Every node in a Kubernetes cluster runs a&nbsp;<code>kube-proxy<\/code>.&nbsp;<code>kube-proxy<\/code>&nbsp;is responsible for implementing a form of virtual IP for&nbsp;<code>Services<\/code>&nbsp;of type.&nbsp;<strong><em>Kubernetes relies on proxying to forward inbound traffic to backends.<\/em><\/strong>\u6ce8\u610f\u8fd9\u91cc\u662f\u7528proxy\u5f15\u5bfcservice\u8bbf\u95ee\u8bf7\u6c42\u5230\u540e\u9762\u7684pod\u3002\u6709\u4e09\u79cdproxy\u65b9\u5f0f\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\/#proxy-mode-userspace\" target=\"_blank\">space proxy mode<\/a>,&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\/#proxy-mode-iptables\" target=\"_blank\">iptables proxy mode<\/a>, and&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\/#proxy-mode-ipvs\" target=\"_blank\">ipvs proxy mode<\/a>. \u524d\u4e24\u79cd\u7528iptables rules\u6765\u4f20\u9012network traffic, \u8fd9\u6837\u7684\u597d\u5904\u662fusing iptables to handle traffic has a lower system overhead, because traffic is handled by Linux netfilter without the need to switch between userspace and the kernel space\u3002\u7b2c\u4e09\u79cd\u6027\u80fd\u66f4\u597d\uff0c\u56e0\u4e3a\u5229\u7528netfilter hook\u94a9\u5b50\u6765\u5f15\u6d41\uff0c\u8fd0\u884c\u5728kernel space\u3002IPVS proxy mode\u7684balancing options:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>rr<\/code>: round-robin<\/li><li><code>lc<\/code>: least connection (smallest number of open connections)<\/li><li><code>dh<\/code>: destination hashing<\/li><li><code>sh<\/code>: source hashing<\/li><li><code>sed<\/code>: shortest expected delay<\/li><li><code>nq<\/code>: never queue<\/li><\/ul>\n\n\n\n<p><strong>Headless<\/strong> \u6709\u65f6\u5019\u4e0d\u9700\u8981VIP\uff0c\u53ef\u4ee5\u8fd9\u6837\u8bbe\u7f6eClusterIP: None\uff0c\u8fd9\u65f6\u6bcf\u4e2aPod\u90fd\u6709DNS\u8bb0\u5f55\uff0c\u901a\u8fc7DNS\u627e\u5230\u7684\u662fPod IP\u3002\u53ef\u4ee5\u4e0eStatefulSet\u7b49\u7ed3\u5408\u4f7f\u7528\uff0c\u53c2\u8003<a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.io\/docs\/tutorials\/stateful-application\/basic-stateful-set\/#creating-a-statefulset\" target=\"_blank\">\u8fd9\u4e2a\u4f8b\u5b50<\/a>\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">DNS<\/h4>\n\n\n\n<p>\u670d\u52a1\u6cbb\u7406\u9700\u8981\u670d\u52a1\u6ce8\u518c\uff0c\u53d1\u73b0\u548cloadbalance\u3002\u4e0a\u9762\u8bb2\u5230\u4e86\uff0cservice\/pod\u7684\u6ce8\u518c\u4fe1\u606f\u662f\u7531kubelet\u6765\u7ef4\u62a4\u7684\uff0c\u90a3\u4e48\u670d\u52a1\u53d1\u73b0\u53ef\u4ee5\u901a\u8fc7ClusterIP\uff0c\u4f46\u4e5f\u4e0d\u592a\u7406\u60f3\uff0c\u56e0\u4e3aIP\u4e5f\u53ef\u80fd\u4f1a\u53d8\u5316\uff0c\u53ef\u4ee5\u7528dns\uff1f\u662f\u7684\uff0ckubernetes\u6b63\u662f\u7528\u4e86DNS\uff08Kubernetes DNS\uff09\u6765\u5f7b\u5e95\u89e3\u51b3\u5185\u90e8\u670d\u52a1\u53d1\u73b0\u7684\u3002Kubernetes DNS<strong>&nbsp;<\/strong>schedules a DNS Pod(or more) and Service on the cluster, and configures the kubelets to tell individual containers to use the DNS Service\u2019s IP to resolve DNS names.<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0c\u96c6\u7fa4\u5185\u8bbf\u95eeservice\u6ca1\u4ec0\u4e48\u969c\u788d\u4e86\uff0c\u90a3\u96c6\u7fa4\u5916\u662f\u600e\u4e48\u8bbf\u95ee\u5230\u4e00\u4e2aservice\u5462\uff1f\u6709\u51e0\u79cd\u9014\u5f84\uff0cNodePort\uff0cLoadbalancer\uff0c\u548cIngress. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">NodePort<\/h4>\n\n\n\n<p>\u5982\u679cService Type\u4e3aNodePort\uff0c\u90a3\u4e48\u8fd9\u4e2aservice\u521b\u5efa\u65f6\u4f1a\u6253\u5f00node\u7684\u67d0\u4e2aPort(30000~32767)\uff0c\u8be5node\u4f1a\u76d1\u542c\u8fd9\u4e2aPort\uff0c\u5c06\u8bbf\u95ee\u5f15\u5bfc\u81f3\u540e\u7aef\u7684\u67d0\u4e2apod\uff0c\u5f53\u7136\u4e5f\u662f\u501f\u52a9\u4e8ekube-proxy\u6765\u5bfb\u627epod\u7684\uff0c\u8bbf\u95eeURI\u4e3aNodeIP:Port\u3002Kubenetes\u4f1a\u6253\u5f00\u6240\u6709node\u6216\u8005\u6307\u5b9anode\u4e0a\u7684\u540c\u4e00\u4e2aPort\uff0c\u56e0\u6b64\u8bbf\u95ee\u4e00\u4e2aservice\u4e0d\u6b62\u4e00\u4e2aNodeIP\u3002\u8fd9\u91cc\u53ef\u4ee5\u8003\u8651\u518d\u52a0\u4e00\u5c42loadbalancer\u3002<\/p>\n\n\n\n<p>\u5f53\u6d41\u91cf\u4ecePod\u8d70\u5411cluster\u5916\u65f6\uff0cPod IP\u4f1a\u901a\u8fc7NAT\u8f6c\u5316\u4e3aNodeIP\uff0c\u5f53\u6d41\u91cf\u4ece\u5916\u90e8\u6d41\u5165\u65f6\uff0cDNAT(Destination NAT)\u8f6c\u5316\u8bbf\u95ee\u76ee\u7684\u5730\u4e3a\u67d0\u4e2aPod\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">LoadBalancer<\/h4>\n\n\n\n<p>\u516c\u6709\u4e91\u63d0\u4f9b\u5546\u4f1a\u63d0\u4f9bload balancer\uff0c\u4e00\u4e2aload balancer\u4f1a\u6709\u4e00\u4e2a\u516c\u7f51IP\u3002Service Type\u4e3aLoadBalancer\u7684Service\u672c\u8d28\u8fd8\u662fNodePort\u7c7b\u578b\uff0c\u4f46\u591a\u4e86\u4e00\u5c42load balancer\uff0c\u56e0\u6b64service\u7684\u8bbf\u95ee\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6bcf\u4e2aservice\u9700\u8981\u4e00\u4e2a\u516c\u7f51IP\uff0c\u6216\u8005\u4e00\u4e2a\u516c\u7f51\u57df\u540d\uff0c\u5982\u679c\u6709\u5f88\u591aservice\uff0c\u663e\u7136\u8fd9\u6837\u4e0d\u592a\u5408\u7406\u3002\u6240\u4ee5Kubernetes\u5f15\u5165\u4e86Ingress\u3002<\/p>\n\n\n\n<p>\u81ea\u5df1\u4e5f\u53ef\u4ee5\u642d\u5efaKubernetes\u7684load balancer\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/metallb.universe.tf\" target=\"_blank\">MetalLB<\/a>\u662f\u4e00\u79cd\u5b9e\u73b0\u65b9\u6848\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ingress<\/h2>\n\n\n\n<p><strong>Ingress<\/strong>&nbsp;\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u53cd\u5411\u4ee3\u7406\uff0c\u6620\u5c04URI(outside cluster)\u5230Service\u4e0a\u3002\u53ef\u4ee5\u5b9a\u4e49Ingress object, kind: Ingress\uff0cingress.spec\u5b9a\u4e49host\/url\u548cbackend\u7684\u6620\u5c04\u5173\u7cfb\uff0c<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/ingress-controllers\">ingress controller<\/a>\u5b9e\u73b0\u8fd9\u79cd\u4ee3\u7406\u3002\u6240\u4ee5\uff0c\u5982\u679c\u7528Ingress\uff0c\u9700\u8981\u6709Ingress Controller\uff0c\u6bd4\u5982<a href=\"https:\/\/kubernetes.github.io\/ingress-nginx\/deploy\/\">ingress-nginx<\/a>\u548c<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/jcmoraisjr\/haproxy-ingress\" target=\"_blank\">haproxy-ingress<\/a>\uff0c\u53ef\u591a\u53ef\u67e5<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/ingress-controllers\">Ingress controllers<\/a>\u3002<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.github.io\/ingress-nginx\/\" target=\"_blank\">ingress-nginx<\/a>\u662fKubernetes ingress controller, \u7528<a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/configure-pod-configmap\/#understanding-configmaps-and-pods\" target=\"_blank\">ConfigMap<\/a>\u6765<a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.github.io\/ingress-nginx\/user-guide\/nginx-configuration\/configmap\/#configuration-options\" target=\"_blank\">\u5b58\u653eNginx\u914d\u7f6e<\/a>\u3002\u6ce8\u610f\u7684\u662fingress-nginx controller\u4f1a\u5728\u5fc5\u8981\u65f6\u91cd\u542fnginx\uff0c\u6bd4\u5982\u5f53configuration\u6709\u53d8\u52a8\u65f6\uff0c\u4f46\u6709\u4e9b\u60c5\u51b5\u4e0d\u7528\u91cd\u542f\uff0c\u6bd4\u5982upstream(end points)\u6709\u53d8\u52a8\uff08pod\u5220\u9664\uff0c\u521b\u5efa\uff09\uff0c\u5b9e\u73b0\u65b9\u5f0f\u662f\u901a\u8fc7<a href=\"https:\/\/github.com\/openresty\/lua-nginx-module\">lua-nginx-module<\/a>\u3002<\/p>\n\n\n\n<p>\u8fdb\u4e00\u6b65\u63a2\u7a76Ingress\u3002Ingress\u662f\u4e00\u79cd\u7279\u6b8a\u7684service\uff0c\u5bf9\u5916\u7aef\u53e3\u4e3a80\/443\uff0c\u533a\u522b\u4e8e\u4e00\u822c\u7684NortPort\u3002Ingress\u5728\u5916\u5c42\u53ef\u5bf9\u63a5load balancer(\u516c\u7f51IP\/\u57df\u540d)\uff0c\u4e5f\u53ef\u4ee5\u7528\u7528HostPort\u5bf9\u5916\u66b4\u9732\u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u5982\u679cCloud Provider\u652f\u6301Loadbalance\uff0c\u76f4\u63a5\u8fd0\u884c\u547d\u4ee4\u5373\u53ef\u83b7\u53d6\u4e00\u4e2aloadbalancer\u7684IP\u3002\u7136\u540e\u521b\u5efa\u4e00\u4e2aKind: Ingress\u914d\u7f6eupstream\u5373\u53ef\u3002<br>$helm install &#8211;name nginx-ingress &#8211;namespace kube-system stable\/nginx-ingress<\/p>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7hostPort\u6765\u66b4\u9732Ingress\uff0c\u7528DaemonSet\u65b9\u5f0f\u90e8\u7f72\u3002Deployment \u90e8\u7f72\u7684\u526f\u672c Pod \u4f1a\u5206\u5e03\u5728\u5404\u4e2a Node \u4e0a\uff0c\u6bcf\u4e2a Node \u90fd\u53ef\u80fd\u8fd0\u884c\u597d\u51e0\u4e2a\u526f\u672c\u3002DaemonSet \u7684\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff1a\u6bcf\u4e2a Node \u4e0a\u6700\u591a\u53ea\u80fd\u8fd0\u884c\u4e00\u4e2a\u526f\u672c\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u9009\u53d6\u4e00\u4e2a\u6216\u8005\u591a\u4e2aNode\u90e8\u7f72Ingress Controller\uff0c\u7136\u540ehelm\u5b89\u88c5\u5230\u8fd9\u4e9bNode\u3002\u5b89\u88c5\u540e\u5373\u53ef\u901a\u8fc7Node IP(80\/443)\u6765\u8bbf\u95eeIngress\u3002\u5982\u679c\u8fd9\u4e9b\u8282\u70b9\u6709\u516c\u7f51IP\u53ef\u4ee5\u7ed1\u5b9aDNS\u6765\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u3002<br>$kubectl label node node_name <strong>node=ingress<\/strong><\/p>\n\n\n\n<p>$helm install stable\/nginx-ingress \\<br>&#8211;namespace kube-system \\<br>&#8211;name nginx-ingress \\<br>&#8211;version=xxx \\<br>&#8211;set controller.kind=DaemonSet \\<br>&#8211;set controller.daemonset.useHostPort=true \\<br>&#8211;set controller.nodeSelector.<strong>node=ingress<\/strong> \\<br>&#8211;set controller.service.type=ClusterIP<\/p>\n\n\n\n<p>Ingress\u5bf9\u5185\u901a\u8fc7\u53cd\u5411\u4ee3\u7406\u5bf9\u63a5\u4e0d\u540c\u7684service\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbeIngress\u914d\u7f6e\u4e3a\u4e24\u4e2a\u5e94\u7528foo.example.com\u548cexample.com\/abc\u7684\u4ee3\u7406\uff0c\u5f53\u5ba2\u6237\u8bbf\u95eefoo.example.com\u65f6\uff0c\u8bbf\u95ee\u8bf7\u6c42\u901a\u8fc7load balancer\u5bfc\u5411Ingress\uff0cIngress\u901a\u8fc7\u914d\u7f6e(path\/service\u6620\u5c04)\u627e\u5230\u76f8\u5e94\u7684Service\uff0c\u63a5\u4e0b\u6765\u901a\u8fc7Kube-proxy\u627e\u5230\u67d0\u4e2aPod\u3002\u8bbf\u95eeexample.com\/abc\u65f6\u4f1a\u6709\u4e00\u6837\u7684\u6d41\u7a0b\uff0c\u53ea\u662fIngress\u7684Path\u4e0d\u540c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-11.png\" alt=\"\" class=\"wp-image-426\" width=\"478\" height=\"371\" srcset=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-11.png 956w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-11-300x233.png 300w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-11-768x596.png 768w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-12-1024x554.png\" alt=\"\" class=\"wp-image-428\" width=\"512\" height=\"277\" srcset=\"https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-12-1024x554.png 1024w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-12-300x162.png 300w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-12-768x415.png 768w, https:\/\/www.funnymuddy.com\/wp-content\/uploads\/2020\/05\/image-12.png 1472w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">network policy<\/h2>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/network-policies\/\" target=\"_blank\">networkpolicy<\/a>\u5141\u8bb8\u81ea\u5b9a\u4e49\u7279\u6b8a\u7684pod-to-pod\uff0c\u6bd4\u5982\u5b9a\u4e49\u4e00\u4e2anetwork policy\uff0c\u4ee4\u67d0\u4e2apod\u4e0d\u80fd\u88ab\u5176\u5b83pod\u8bbf\u95ee\u3002<\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_379\" class=\"pvc_stats all  \" data-element-id=\"379\" style=\"\"><i class=\"pvc-stats-icon small\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/plugins\/page-views-count\/ajax-loader.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Pod\u5185containers Pod\u5185\u6709\u4e00\u4e2a\u6216\u8005\u591a\u4e2acontainer\uff0c\u5171\u4eabnetworking(IP\/Por&hellip;&nbsp;<a href=\"https:\/\/www.funnymuddy.com\/?p=379\" class=\"\" rel=\"bookmark\">\u9605\u8bfb\u66f4\u591a &raquo;<span class=\"screen-reader-text\">kubernetes network<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_379\" class=\"pvc_stats all  \" data-element-id=\"379\" style=\"\"><i class=\"pvc-stats-icon small\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" src=\"https:\/\/www.funnymuddy.com\/wp-content\/plugins\/page-views-count\/ajax-loader.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[20],"class_list":["post-379","post","type-post","status-publish","format-standard","hentry","category-6","tag-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=\/wp\/v2\/posts\/379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379"}],"version-history":[{"count":28,"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=\/wp\/v2\/posts\/379\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=\/wp\/v2\/posts\/379\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.funnymuddy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}