解決兩宿主機(jī)容器之間的透明訪問,如不進(jìn)行優(yōu)化,容器之間的訪問,日志記錄為宿主機(jī)的IP地址。
1、安裝iptables-services組件
[root@test-nodes1 ~]# yum -y install iptables-services
[root@test-nodes1 ~]# systemctl start iptables
[root@test-nodes1 ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
-----------------------------------------------------------------------------------------------
2、把以下iptable記錄的偽裝轉(zhuǎn)向刪除
[root@test-nodes1 ~]# iptables-save |grep -i postrouting
:POSTROUTING ACCEPT [68:4098]
:KUBE-POSTROUTING - [0:0]
-A POSTROUTING -m comment --comment "kubernetes postrouting rules" -j KUBE-POSTROUTING
-A POSTROUTING -s 172.7.21.0/24 ! -o docker0 -j MASQUERADE #刪除此條
-A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark 0x4000/0x4000 -j MASQUERADE
-----------------------------------------------------------------------------------------------
3、刪除該記錄
[root@test-nodes1 ~]# iptables -t nat -D POSTROUTING -s 172.7.21.0/24 ! -o docker0 -j MASQUERADE
-----------------------------------------------------------------------------------------------
4、插入一條新的記錄(排除對(duì)172.7.0.0/16網(wǎng)絡(luò)訪問的偽裝)
[root@test-nodes1 ~]# iptables -t nat -I POSTROUTING -s 172.7.21.0/24 ! -d 172.7.0.0/16 ! -o docker0 -j MASQUERADE
-----------------------------------------------------------------------------------------------
5、查看是否生效
[root@test-nodes1 ~]# iptables-save |grep -i postrouting
:POSTROUTING ACCEPT [13:814]
:KUBE-POSTROUTING - [0:0]
-A POSTROUTING -s 172.7.21.0/24 ! -d 172.7.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -m comment --comment "kubernetes postrouting rules" -j KUBE-POSTROUTING
-A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark 0x4000/0x4000 -j MASQUERADE
-----------------------------------------------------------------------------------------------
6、刪除iptables上所有reject拒絕規(guī)則
[root@test-nodes1 ~]# iptables-save | grep -i reject
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
[root@test-nodes1 ~]# iptables -t filter -D INPUT -j REJECT --reject-with icmp-host-prohibited
[root@test-nodes1 ~]# iptables -t filter -D FORWARD -j REJECT --reject-with icmp-host-prohibited
[root@test-nodes1 ~]# iptables-save | grep -i reject
-----------------------------------------------------------------------------------------------
7、保存iptables規(guī)則
[root@test-nodes1 ~]# iptables-save > /etc/sysconfig/iptables
網(wǎng)站名稱:K8S之Flannel之SNAT規(guī)劃優(yōu)化-創(chuàng)新互聯(lián)
鏈接地址:http://muchs.cn/article8/dpggip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、虛擬主機(jī)、手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、建站公司、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容