日常更新
This commit is contained in:
10
ansible/files/06-01/README.md
Normal file
10
ansible/files/06-01/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# 06-01(NetworkPolicy 与连通性排障)
|
||||
|
||||
| 文件 | 说明 |
|
||||
|------|------|
|
||||
| `networkpolicy-traefik-egress.example.yaml` | Traefik 出站示例:后端命名空间、Service CIDR、DNS |
|
||||
| `networkpolicy-backend-ingress.example.yaml` | 后端仅允许来自 `kube-system`(Traefik)的入站示例 |
|
||||
|
||||
- **手动**:复制为正式名后 `kubectl apply -f ...`,并按集群实际 **namespace / 标签 / CIDR** 修改(见 [docs/06-01-k3s-networkpolicy-故障排查.md](../../../docs/06-01-k3s-networkpolicy-故障排查.md))。
|
||||
- **自动**:`./ansible/bin/verify.sh run 06-01`(noop + 基线;策略真源以本目录为准,与手工 `kubectl` 一致)。
|
||||
- 示例文件名含 `example.`,默认验证流程跳过对其的 `kubectl dry-run`。
|
||||
@@ -0,0 +1,21 @@
|
||||
# 示例:后端 Namespace 仅允许来自 kube-system(Traefik)的入站
|
||||
# 将 namespace、podSelector、端口改为你的应用标签与 Service 端口。
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: backend-from-traefik-example
|
||||
namespace: default
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
policyTypes:
|
||||
- Ingress
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: kube-system
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
@@ -0,0 +1,32 @@
|
||||
# 示例:为 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 CIDR(k3s 默认常为 10.43.0.0/16,请与集群一致)
|
||||
- to:
|
||||
- ipBlock:
|
||||
cidr: 10.43.0.0/16
|
||||
# 集群 DNS
|
||||
- ports:
|
||||
- protocol: UDP
|
||||
port: 53
|
||||
- protocol: TCP
|
||||
port: 53
|
||||
Reference in New Issue
Block a user