Files
Deploy-Laboratory/ansible/files/06-01/networkpolicy-traefik-egress.example.yaml
2026-03-29 09:08:01 +08:00

33 lines
890 B
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 示例:为 Traefik 放行出站(按实际 namespace 与标签调整)
# 适用场景:后端在其它命名空间、需访问集群 DNS 与 Service VIP。
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: traefik-egress-lab-example
namespace: kube-system
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: traefik
policyTypes:
- Egress
egress:
# 访问任意命名空间内 Pod可按需收窄为 namespaceSelector + podSelector
- to:
- namespaceSelector: {}
ports:
- protocol: TCP
port: 8080
- protocol: TCP
port: 8000
# Service CIDRk3s 默认常为 10.43.0.0/16请与集群一致
- to:
- ipBlock:
cidr: 10.43.0.0/16
# 集群 DNS
- ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53