[英]VPC native Clusters in GKE can't communicate in GKE 1.14
我在 K8s 1.14.10 上創建了兩個單獨的 GKE 集群。
我遵循了這個和 IP 偽裝代理文檔。 我嘗試使用客戶端 pod 和服務器 pod 來交換消息來對此進行測試。 我正在使用內部節點 IP 發送消息並創建一個 ClusterIP 來公開 Pod。
我已允許對防火牆規則中的每個實例的請求以進行入口和出口,即0.0.0.0/0 。 圖片:這是我創建的集群的描述IP 偽裝代理的配置 map 與文檔中的相同。 我可以從 pod 中 ping 另一個節點,但 curl 請求說連接被拒絕並且 tcpdump 顯示沒有數據。
問題:我需要在 gke 1.14 中從集群 A 與集群 B 通信,並將 ipmasquerading 設置為 true。 我要么連接被拒絕,要么 i/o 超時。 我嘗試過使用內部和外部節點 IP 以及使用負載均衡器。
您提供了相當籠統的信息,沒有詳細信息,我無法提供具體的場景答案。 這可能與您如何創建集群或其他防火牆設置有關。 因此,我將提供正確的步驟來創建和配置 2 個帶有 firewall 和masquerade
的集群。 也許您將能夠找到您錯過或錯誤配置的步驟。
集群配置(節點、pods、svc)在答案的底部。
1.創建VPC和2個集群
在文檔中它說大約 2 個不同的項目,但您可以在一個項目中完成。 可以在 GKE 文檔中找到 VPC 創建和 2 個集群的良好示例。 創建 VPC和Crate 2 集群。 在集群Tier1
中,您現在可以啟用NetworkPolicy
,而不是以后再啟用它。 之后,您將需要創建防火牆規則。 您還需要將ICMP
協議添加到防火牆規則。
此時,您應該能夠在 2 個集群的節點之間 ping 通。
有關其他防火牆規則(允許 pod、svc 等之間的連接),請查看此文檔。
2.啟用IP偽裝代理
如文檔中所述,運行IPMasquerade
:
如果滿足以下一項或多項條件,則 ip-masq-agent DaemonSet 會作為帶有 --nomasq-all-reserved-ranges 參數的插件自動安裝在 GKE 集群中:
集群有一個網絡策略。
或者
Pod 的 CIDR 范圍不在 10.0.0.0/8 之內。
這意味着tier-2-cluster
在kube-system
命名空間中已經有ip-masq-agent
(因為The Pod's CIDR range is not within 10.0.0.0/8.
)。 如果您在創建tier-1-cluster
期間啟用了NetworkPolicy
,它應該也已安裝。 如果沒有,您將需要使用以下命令啟用它:
$ gcloud container clusters update tier-1-cluster --update-addons=NetworkPolicy=ENABLED --zone=us-central1-a
要驗證一切是否正常,您必須檢查是否創建了Daemonset ip-masq-agent
pod。 (節點的每個 pod)。
$ kubectl get ds ip-masq-agent -n kube-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
ip-masq-agent 3 3 3 3 3 beta.kubernetes.io/masq-agent-ds-ready=true 168m
如果您將 SSH 連接到您的任何節點,您將能夠看到默認的iptables
條目。
$ sudo iptables -t nat -L IP-MASQ
Chain IP-MASQ (1 references)
target prot opt source destination
RETURN all -- anywhere 169.254.0.0/16 /* ip-masq: local traffic is not subject to MASQUERADE */
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq: RFC 1918 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 172.16.0.0/12 /* ip-masq: RFC 1918 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 192.168.0.0/16 /* ip-masq: RFC 1918 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 240.0.0.0/4 /* ip-masq: RFC 5735 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 192.0.2.0/24 /* ip-masq: RFC 5737 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 198.51.100.0/24 /* ip-masq: RFC 5737 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 203.0.113.0/24 /* ip-masq: RFC 5737 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 100.64.0.0/10 /* ip-masq: RFC 6598 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 198.18.0.0/15 /* ip-masq: RFC 6815 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 192.0.0.0/24 /* ip-masq: RFC 6890 reserved range is not subject to MASQUERADE */
RETURN all -- anywhere 192.88.99.0/24 /* ip-masq: RFC 7526 reserved range is not subject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq: outbound traffic is subject to MASQUERADE (must be last in chain) */
3. 部署測試應用
我使用了GKE 文檔中的 Hello 應用程序並部署在兩個集群上。 此外,我還部署了 ubuntu 映像進行測試。
4.為IPMasquerade應用正確的配置這個配置需要在source
集群上。
簡而言之,如果目標 CIDR 在nonMasqueradeCIDRs:
中,它將顯示它內部 IP,否則它將顯示 NodeIP 作為源。
保存到文本下方的文件config
:
nonMasqueradeCIDRs:
- 10.0.0.0/8
resyncInterval: 2s
masqLinkLocal: true
創建 IPMasquarade ConfigMap
$ kubectl create configmap ip-masq-agent --from-file config --namespace kube-system
它將覆蓋iptables
配置
$ sudo iptables -t nat -L IP-MASQ
Chain IP-MASQ (2 references)
target prot opt source destination
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: local traffic is not subject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic is subject to MASQUERADE (must be last in chain) */
5. 測試:
當 IP 被偽裝時
SSH 到 Node 形成Tier2
集群並運行:
sudo toolbox bash
apt-get update
apt install -y tcpdump
現在您應該使用下面的命令收聽。 端口32502
是來自Tier 2
集群的NodePort
服務
tcpdump -i eth0 -nn -s0 -v port 32502
在 Cluster Tier1
中,您需要輸入 ubuntu pod 和 curl NodeIP:NodePort
$ kubectl exec -ti ubuntu -- bin/bash
您需要安裝 curl apt-get install curl
。
curl NodeIP:NodePort(正在偵聽的節點,來自集群第 2 層服務的 NodePort)。
命令行界面:
root@ubuntu:/# curl 172.16.4.3:32502
Hello, world!
Version: 2.0.0
Hostname: hello-world-deployment-7f67f479f5-h4wdm
在 Node 上,您可以看到如下條目:
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
12:53:30.321641 IP (tos 0x0, ttl 63, id 25373, offset 0, flags [DF], proto TCP (6), length 60)
10.0.4.4.56018 > 172.16.4.3.32502: Flags [S], cksum 0x8648 (correct), seq 3001889856
10.0.4.4
是NodeIP
pod 所在的 NodeIP。
當 IP 未被偽裝時
從集群第 1 層移除ConfigMap
$ kubectl delete cm ip-masq-agent -n kube-system
將文件config
CIDR 更改為172.16.4.0/22
,這是Tier 2
節點池並重新應用 CM
$ kubectl create configmap ip-masq-agent --from-file config --namespace kube-system
SSH 從第 1 層的任何節點檢查iptables rules
是否已更改。
sudo iptables -t nat -L IP-MASQ
Chain IP-MASQ (2 references)
target prot opt source destination
RETURN all -- anywhere 172.16.4.0/22 /* ip-masq-agent: local traffic is not subject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic is subject to MASQUERADE (must be last in chain) */
現在進行測試,我再次使用了 Ubuntu 吊艙和 curl 和以前一樣的 ip。
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
13:16:50.316234 IP (tos 0x0, ttl 63, id 53160, offset 0, flags [DF], proto TCP (6), length 60)
10.4.2.8.57876 > 172.16.4.3.32502
10.4.2.8
是 Ubuntu 吊艙的內部 IP。
測試配置:
一級
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/hello-world-deployment-7f67f479f5-b2qqz 1/1 Running 0 15m 10.4.1.8 gke-tier-1-cluster-default-pool-e006097b-5tnj <none> <none>
pod/hello-world-deployment-7f67f479f5-shqrt 1/1 Running 0 15m 10.4.2.5 gke-tier-1-cluster-default-pool-e006097b-lfvh <none> <none>
pod/hello-world-deployment-7f67f479f5-x7jvr 1/1 Running 0 15m 10.4.0.8 gke-tier-1-cluster-default-pool-e006097b-1wbf <none> <none>
ubuntu 1/1 Running 0 91s 10.4.2.8 gke-tier-1-cluster-default-pool-e006097b-lfvh <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/hello-world NodePort 10.0.36.46 <none> 60000:31694/TCP 14m department=world,greeting=hello
service/kubernetes ClusterIP 10.0.32.1 <none> 443/TCP 115m <none>
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node/gke-tier-1-cluster-default-pool-e006097b-1wbf Ready <none> 115m v1.14.10-gke.36 10.0.4.2 35.184.38.21 Container-Optimized OS from Google 4.14.138+ docker://18.9.7
node/gke-tier-1-cluster-default-pool-e006097b-5tnj Ready <none> 115m v1.14.10-gke.36 10.0.4.3 35.184.207.20 Container-Optimized OS from Google 4.14.138+ docker://18.9.7
node/gke-tier-1-cluster-default-pool-e006097b-lfvh Ready <none> 115m v1.14.10-gke.36 10.0.4.4 35.226.105.31 Container-Optimized OS from Google 4.14.138+ docker://18.9.7<none> 100m v1.14.10-gke.36 10.0.4.4 35.226.105.31 Container-Optimized OS from Google 4.14.138+ docker://18.9.7
2級
$ kubectl get pods,svc,nodes -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/hello-world-deployment-7f67f479f5-92zvk 1/1 Running 0 12m 172.20.1.5 gke-tier-2-cluster-default-pool-57b1cc66-xqt5 <none> <none>
pod/hello-world-deployment-7f67f479f5-h4wdm 1/1 Running 0 12m 172.20.1.6 gke-tier-2-cluster-default-pool-57b1cc66-xqt5 <none> <none>
pod/hello-world-deployment-7f67f479f5-m85jn 1/1 Running 0 12m 172.20.1.7 gke-tier-2-cluster-default-pool-57b1cc66-xqt5 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/hello-world NodePort 172.16.24.206 <none> 60000:32502/TCP 12m department=world,greeting=hello
service/kubernetes ClusterIP 172.16.16.1 <none> 443/TCP 113m <none>
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node/gke-tier-2-cluster-default-pool-57b1cc66-84ng Ready <none> 112m v1.14.10-gke.36 172.16.4.2 35.184.118.151 Container-Optimized OS from Google 4.14.138+ docker://18.9.7
node/gke-tier-2-cluster-default-pool-57b1cc66-mlmn Ready <none> 112m v1.14.10-gke.36 172.16.4.3 35.238.231.160 Container-Optimized OS from Google 4.14.138+ docker://18.9.7
node/gke-tier-2-cluster-default-pool-57b1cc66-xqt5 Ready <none> 112m v1.14.10-gke.36 172.16.4.4 35.202.94.194 Container-Optimized OS from Google 4.14.138+ docker://18.9.7
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.