我正在使用下面的 NetworkPolicy 来允许 HTTP 和 HTTPS 端口上的出口,但是wget https://google.com
在应用网络策略时运行不起作用。域名已解析(DNS 出口规则有效)但连接到外部主机超时。
我已经尝试过使用 cilium 的 minikube 和使用 azure-npm 的 Azure,以防网络策略控制器出现问题,但两者的行为相同。我很困惑,因为我对 DNS 出口使用相同的方法(有效),但对于其他端口却失败了。
是什么阻止了 HTTP/HTTPS 端口的出口?
Kubernetes 版本 1.11.5
apiVersion: extensions/v1beta1
kind: NetworkPolicy
metadata:
name: my-netpolicy
spec:
egress:
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
- ports:
- port: 443
protocol: UDP
- port: 443
protocol: TCP
- port: 80
protocol: UDP
- port: 80
protocol: TCP
podSelector:
matchLabels:
my-label: my-app
(是的,UDP 规则可能是不必要的,但在这里尝试一切)
(我也在wget
私人服务器上尝试过,以防谷歌/等阻止 Azure IP,同样的结果)
(我也尝试过匹配入口规则,因为“为什么不”,结果相同)
kubectl describe
关于网络策略:
Name: my-netpolicy
Namespace: default
Created on: 2019-01-21 19:00:04 +0000 UTC
Labels: ...
Annotations: <none>
Spec:
PodSelector: ...
Allowing ingress traffic:
To Port: 8080/TCP
From: <any> (traffic not restricted by source)
----------
To Port: https/UDP
To Port: https/TCP
To Port: http/TCP
To Port: http/UDP
From: <any> (traffic not restricted by source)
Allowing egress traffic:
To Port: 53/UDP
To Port: 53/TCP
To: <any> (traffic not restricted by source)
----------
To Port: https/UDP
To Port: https/TCP
To Port: http/UDP
To Port: http/TCP
To: <any> (traffic not restricted by source)
Policy Types: Ingress, Egress
最小的可重现示例:
apiVersion: v1
kind: Pod
metadata:
name: netpolicy-poc-pod
labels:
name: netpolicy-poc-pod
spec:
containers:
- name: poc
image: ubuntu:18.04
command: ["bash", "-c", "while true; do sleep 1000; done"]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: netpolicy-poc
spec:
podSelector:
matchLabels:
name: netpolicy-poc-pod
egress:
- ports:
- port: 80
protocol: UDP
- port: 80
protocol: TCP
- port: 443
protocol: UDP
- port: 443
protocol: TCP
- port: 53
protocol: UDP
- port: 53
protocol: TCP
ingress: []
然后:
kubectl exec -it netpolicy-poc /bin/bash
apt update
apt install wget -y
wget https://google.com