问题描述
我正在 K3s 上为我的应用实施 kubernetes 网络策略。我想允许 egress
(从 pod 到互联网的外部调用)用于端口 443
,即 https
调用 only 并拒绝/阻止80
端口上的所有出口调用,即 http
。简而言之,允许 https
出口调用并拒绝 http
出口调用。
我正在使用以下 custom-dns.yaml
文件对此进行测试:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: foo-deny-egress
spec:
podSelector:
matchLabels:
app: foo
policyTypes:
- Egress
egress:
# allow DNS resolution
- ports:
- port: 443
protocol: UDP
- port: 443
protocol: TCP
在 kubectl apply -f custom-dns.yaml
之后,我创建并登录到 pod :kubectl run --restart=Never pod-v1 --image=busybox -i -t -l app=foo
并通过命令测试 http 和 https 网址:
wget https://www.google.com
-
wget http://drive.google.com/drive/u/0/my-drive
两个 wget 命令都给出了 wget: bad address
错误。
但是当我不应用此网络策略时,相同的 wget 命令正在工作并从同一个 pod 给出以下结果:
我。
wget https://www.google.com
Connecting to www.google.com (172.217.167.164:443)
wget: note: TLS certificate validation not implemented
saving to 'index.html'
index.html 100% |******************************************************| 15264 0:00:00 ETA
'index.html' saved
ii.
wget http://drive.google.com/drive/u/0/my-drive
Connecting to drive.google.com (142.250.192.46:80)
Connecting to drive.google.com (142.250.192.46:443)
wget: note: TLS certificate validation not implemented
Connecting to accounts.google.com (142.250.192.77:443)
saving to 'my-drive'
my-drive 100% |******************************************************| 92019 0:00:00 ETA
'my-drive' saved
iii. Telnet
到 google.com IP 172.217.167.164
,带有 80
和 443
端口
#telnet 172.217.166.164 80
Connected to 172.217.166.164
^]q
# telnet 172.217.166.164 443
Connected to 172.217.166.164
^]
iv. 类似 Telnet
到 drive.com IP 142.250.192.46
,带有 80
和 443
端口
我在这里遗漏了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)