How can egress from a Kubernetes pod be limited to only specific FQDN/DNS with Azure CNI Network Policies?
This is something that can be achieved with:
Istio
apiVersion: config.istio.io/v1alpha2
kind: EgressRule
metadata:
name: googleapis
namespace: default
spec:
destination:
service: "*.googleapis.com"
ports:
- port: 443
protocol: https
Cilium
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "fqdn"
spec:
endpointSelector:
matchLabels:
app: some-pod
egress:
- toFQDNs:
- matchName: "api.twitter.com"
- toEndpoints:
- matchLabels:
"k8s:io.kubernetes.pod.namespace": kube-system
"k8s:k8s-app": kube-dns
toPorts:
- ports:
- port: "53"
protocol: ANY
rules:
dns:
- matchPattern: "*"
OpenShift
apiVersion: network.openshift.io/v1
kind: EgressNetworkPolicy
metadata:
name: default-rules
spec:
egress:
- type: Allow
to:
dnsName: www.example.com
- type: Deny
to:
cidrSelector: 0.0.0.0/0
How can something similar be done with Azure CNI Network Policies?
3条答案
按热度按时间lhcgjxsq1#
AKS上不支持具有FQDN/DNS规则的ATM网络策略。
如果您使用Azure CNI和Azure策略插件,您将获得默认的Kubernetes网络策略。
如果您使用Azure CNI & Calico Policy Plugin,您可以获得高级功能,如全球网络策略,但不能获得FQDN/DNS。不幸的是,这是Calico Cloud上的付费功能。
3j86kqsm2#
应用K8s网络策略
`
`
参考https://kubernetes.io/docs/concepts/services-networking/network-policies/
jum4pzuy3#
如果有人从谷歌点击此页面:
我找到了一个解决方案,它在我的云提供商(OpenTelekomCloud)上运行得很好,可能在许多其他云提供商上也会运行得很好。
有一个名为gke-fqdnnetworkpolicies-golang的项目
通过定义自定义资源
它将解析FQDN,生成最终的网络策略,并每30秒更新一次记录。这是最终策略的外观
我必须在yaml(从发布页面下载)中将以下权限附加到clusterRolefqdnnetworkpolicies-manager-role,以使其在GKE之外工作