我正在K3s上为我的应用程序实现kubernetes网络策略。我希望允许egress (从pod到internet的外部调用)用于端口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 url:
wget https://www.google.comwget http://drive.google.com/drive/u/0/my-drive 这两个wget命令都会导致wget: bad address错误。
但是,当我不应用此网络策略时,相同的wget命令正在工作&给出以下结果来自相同的结束符:
i.
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' savedii.
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' savediii. Telnet to 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.与drive.com IP 142.250.192.46类似,80 & 443端口正在发生
我在这里错过了什么?
发布于 2021-07-06 19:34:01
您在文章中提到的
- Setup a default deny policy for egress任一
- create another egress policy where you deny egress on port 80https://stackoverflow.com/questions/68271660
复制相似问题