経緯 ● 分からないまま運用するのは怖い ● というわけで調べた ○ GKE/Kubernetes でなぜ Pod と通信できるのか ○ http://qiita.com/apstndb/items/9d13230c666db80e74d0 ● Google Cloud Next '17 にて Kubernetes の Tech Lead Tim Hockin から GKE/Kubernetes ネットワークの解説! ○ The ins and outs of networking in Google Container Engine and Kubernetes ○ https://www.youtube.com/watch?v=y2bhV81MfKQ
Kubernetes の通信 Cluster Networking より ● Pod 内コンテナ間通信(localhost 通信) ● Pod の通信(Kubernetes ネットワーク) ● Pod から Service への通信(ClusterIP Service) ● クラスタ外部から Service への通信(NodePort, LoadBalancer Service)
GCE/GKE での Pod からクラスタ外への通信 ● Pod の IP アドレスはプライベート ○ インターネットとの通信不可 ● インターネットあてのパケットは送信元を Node(GCE インスタンス) の IP アドレスに変換 ○ Source NAT(別名 IP マスカレード) -A POSTROUTING ! -d 10.0.0.0/8 -m comment --comment "kubenet: SNAT for outbound traffic from cluster" -m addrtype ! --dst-type LOCAL -j MASQUERADE
余談 - プライベートネットワークから Pod への通信 ● 実はプライベートネットワーク内なら GKE クラスタの外との直 接通信も可能 ● > NOTE: This is environment specific. Some environments will not need any masquerading at all. Others, such as GCE, will not allow pod IPs to send traffic to the internet, but have no problem with them inside your GCE Project. ○ from Creating a Custom Cluster from Scratch