Remove blank lines after code block markers

This commit is contained in:
yeasy
2026-03-21 22:36:09 -07:00
parent 312f8fea42
commit 9ac19d79ee
132 changed files with 0 additions and 1517 deletions

View File

@@ -29,13 +29,11 @@ veth 对
容器 B (192.168.0.3,不同宿主机)
```
#### 创建和使用 Overlay 网络
**Docker Swarm 模式下的 Overlay 网络**
```bash
# 初始化 Swarm创建集群
docker swarm init
@@ -58,11 +56,9 @@ docker service create --name web \
# 验证服务跨节点通信
docker service ps web
```
**单机 Overlay 网络模拟Linux 容器**
```bash
# 创建自定义 overlay 网络
docker network create --driver overlay custom-overlay
@@ -77,11 +73,9 @@ docker exec container1 curl http://container2
# 检查网络配置
docker network inspect custom-overlay
```
#### Overlay 网络性能优化
```bash
# 调整 MTUMaximum Transmission Unit避免分片
# VXLAN 开销 50 字节,物理 MTU 1500建议设置为 1450
docker network create --driver overlay \
@@ -113,7 +107,6 @@ networks:
driver_opts:
com.docker.network.driver.mtu: 1450
```
### 9.7.2 CNI 插件生态概览
容器网络接口CNI是容器编排平台尤其是 Kubernetes的标准化网络接口不同的 CNI 插件提供不同的网络能力
@@ -125,7 +118,6 @@ networks:
Calico 使用 BGP 协议进行路由支持网络策略和 eBPF 加速
```yaml
# Kubernetes 中安装 Calico
apiVersion: v1
kind: ConfigMap
@@ -154,13 +146,11 @@ data:
]
}
```
**Flannel - 简单可靠的 Overlay**
Flannel 提供简单的 overlay 网络实现适合小到中等规模的集群
```bash
# 安装 Flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
@@ -201,13 +191,11 @@ data:
}
EOF
```
**Cilium - eBPF 驱动的先进网络**
Cilium 使用 eBPF 在内核级别实现网络策略和可观测性性能优异
```bash
# 安装 Cilium
helm repo add cilium https://helm.cilium.io
helm install cilium cilium/cilium \
@@ -222,13 +210,11 @@ helm upgrade cilium cilium/cilium \
--set hubble.enabled=true \
--set hubble.ui.enabled=true
```
**Weave - 跨主机网络通信**
Weave 提供简单的跨主机通信支持加密和多播
```bash
# Docker 中使用 Weave 网络
docker run -d --name weave \
--net=host \
@@ -239,7 +225,6 @@ docker run -d --name weave \
# 连接到 Weave 网络
docker run -d --network weave --name web nginx:latest
```
**CNI 插件对比表**
| 特性 | Calico | Flannel | Cilium | Weave |
@@ -270,13 +255,11 @@ Docker 内嵌 DNS 服务器 (127.0.0.11)
DNS 响应 → 容器缓存 → 应用
```
#### 配置容器 DNS
**在运行时指定 DNS**
```bash
# 单个容器
docker run -d \
--dns 8.8.8.8 \
@@ -294,7 +277,6 @@ docker run -d \
# 查看容器 DNS 配置
docker exec <container_id> cat /etc/resolv.conf
```
**Docker Compose DNS 配置**
```yaml
@@ -325,7 +307,6 @@ networks:
# nameserver 8.8.8.8
# nameserver 1.1.1.1
```
**Docker 守护进程级别配置**
```json
@@ -336,13 +317,11 @@ networks:
"registry-mirrors": ["https://mirror.example.com"]
}
```
#### 自定义服务发现
**使用 Docker 内建 DNS 的服务发现**
```bash
# 创建自定义网络
docker network create mynet
@@ -356,7 +335,6 @@ docker run -it --network mynet busybox sh
# ping web # 自动解析到 web 容器 IP
# ping db # 自动解析到 db 容器 IP
```
**Compose 服务名自动发现**
```yaml
@@ -383,11 +361,9 @@ services:
# frontend 容器可以直接访问 http://backend:8080
# backend 容器可以直接访问 postgres://database:5432
```
#### DNS 性能优化
```bash
# 检查 DNS 延迟
time docker exec <container> nslookup www.example.com
@@ -417,7 +393,6 @@ kubectl patch deployment -n kube-system coredns --patch '{
}
}'
```
### 9.7.4 网络策略实践
网络策略定义了容器间的流量控制规则是微服务架构中的安全基础
@@ -438,7 +413,6 @@ spec:
- Ingress
# 不指定 ingress 规则,表示拒绝所有入站流量
```
**允许特定来源的入站流量**
```yaml
@@ -461,7 +435,6 @@ spec:
- protocol: TCP
port: 8080
```
**允许出站流量到数据库**
```yaml
@@ -500,7 +473,6 @@ spec:
- protocol: TCP
port: 443
```
#### 微服务网络策略示例
```yaml
@@ -625,7 +597,6 @@ spec:
- protocol: TCP
port: 5432
```
#### 使用 Calico/Cilium 的高级网络策略
**L7 应用层策略 Cilium 支持**
@@ -659,7 +630,6 @@ spec:
sourceIPs:
- "10.0.0.0/8"
```
### 9.7.5 跨主机容器通信方案对比
#### 方案对比表
@@ -675,7 +645,6 @@ spec:
#### 选择建议
```bash
# 1. 开发环境:使用 Bridge 网络
docker network create my-app
docker compose up # 默认使用 bridge
@@ -692,13 +661,11 @@ helm install cilium cilium/cilium --namespace kube-system
# 5. 需要多云/跨域:使用 Weave
```
### 9.7.6 网络故障排查
**常见网络问题诊断**
```bash
# 1. 容器无法访问外部网络
docker exec <container> ping 8.8.8.8
docker exec <container> cat /etc/resolv.conf