Multus CNI 12-Factor
Multus CNI 12 Factor App Kubernetes Multi-Network Pod Interface macvlan ipvlan SR-IOV Storage Management Telco NFV Production
| Network | CNI Plugin | Use Case | Performance |
|---|---|---|---|
| Default (Pod) | Calico/Cilium/Flannel | Service-to-Service Traffic | Standard |
| Storage | macvlan/SR-IOV | Ceph NFS iSCSI Replication | High (Dedicated) |
| Management | macvlan/bridge | Monitoring SSH Admin | Standard |
| Data Plane | SR-IOV/DPDK | NFV 5G Packet Processing | Very High (Near-native) |
Network Configuration
# === Multus CNI Network Setup ===
# Install Multus CNI
# kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml
#
# Verify
# kubectl get pods -n kube-system | grep multus
# NetworkAttachmentDefinition - Storage Network
# apiVersion: "k8s.cni.cncf.io/v1"
# kind: NetworkAttachmentDefinition
# metadata:
# name: storage-network
# namespace: default
# spec:
# config: '{
# "cniVersion": "0.3.1",
# "type": "macvlan",
# "master": "eth1",
# "mode": "bridge",
# "ipam": {
# "type": "whereabouts",
# "range": "10.10.0.0/24",
# "gateway": "10.10.0.1"
# }
# }'
# Pod with Multiple Networks
# apiVersion: v1
# kind: Pod
# metadata:
# name: my-app
# annotations:
# k8s.v1.cni.cncf.io/networks: storage-network, mgmt-network
# spec:
# containers:
# - name: app
# image: my-app:latest
# env:
# - name: STORAGE_ENDPOINT # 12-Factor: Config in Env
# value: "10.10.0.100:9000"
# - name: MGMT_ENDPOINT
# value: "10.20.0.100:8080"
from dataclasses import dataclass
@dataclass
class NetworkDef:
name: str
cni_type: str
subnet: str
purpose: str
ipam: str
networks = [
NetworkDef("default-pod-network",
"calico (Default CNI)",
"10.244.0.0/16",
"Service-to-Service ClusterIP NodePort",
"Calico IPAM (Auto)"),
NetworkDef("storage-network",
"macvlan (master: eth1)",
"10.10.0.0/24",
"Ceph Storage Replication Backup",
"whereabouts (Cross-node)"),
NetworkDef("mgmt-network",
"macvlan (master: eth2)",
"10.20.0.0/24",
"Monitoring Prometheus SSH Admin",
"whereabouts (Cross-node)"),
NetworkDef("data-plane",
"SR-IOV (VF from PF)",
"10.30.0.0/24",
"NFV 5G High-throughput Data",
"host-local (Per-node)"),
]
print("=== Network Definitions ===")
for n in networks:
print(f" [{n.name}] CNI: {n.cni_type}")
print(f" Subnet: {n.subnet}")
print(f" Purpose: {n.purpose}")
print(f" IPAM: {n.ipam}")
12-Factor Compliance
# === 12-Factor App with Multus ===
@dataclass
class FactorCompliance:
factor: str
principle: str
multus_implementation: str
example: str
factors = [
FactorCompliance("3. Config",
"Config ใน Environment Variable ไม่ Hardcode",
"Network Endpoint เก็บใน ConfigMap/Env ไม่ Hardcode IP",
"STORAGE_ENDPOINT=10.10.0.100:9000 ใน Env"),
FactorCompliance("4. Backing Services",
"Backing Service เป็น Attached Resource เปลี่ยนได้",
"Network เป็น Attached Resource เปลี่ยน NetworkAttachmentDefinition ได้",
"เปลี่ยน Storage Network จาก macvlan เป็น SR-IOV โดยไม่แก้ App"),
FactorCompliance("6. Stateless Processes",
"App เป็น Stateless ไม่เก็บ State ใน Process",
"Network State อยู่ที่ CNI/IPAM ไม่ใช่ App",
"Pod ถูก Reschedule ได้ IPAM จัดการ IP ใหม่"),
FactorCompliance("8. Concurrency",
"Scale ด้วย Process ไม่ใช่ Thread",
"Scale Pod ได้ Multus จัดการ Network Interface อัตโนมัติ",
"kubectl scale --replicas=10 ทุก Pod ได้ Network ครบ"),
FactorCompliance("9. Disposability",
"เริ่ม/หยุดเร็ว Graceful Shutdown",
"Pod Start: CNI Attach Network Interface เร็ว Pod Stop: CNI Release IP",
"Network Attach/Detach < 1 วินาที"),
FactorCompliance("10. Dev/Prod Parity",
"Environment เหมือนกัน",
"ใช้ NetworkAttachmentDefinition เหมือนกันทุก Env",
"Dev Staging Production ใช้ YAML เดียวกัน เปลี่ยน Subnet"),
]
print("=== 12-Factor Compliance ===")
for f in factors:
print(f"\n [{f.factor}] {f.principle}")
print(f" Multus: {f.multus_implementation}")
print(f" Example: {f.example}")
Production Monitoring
# === Production Monitoring & Troubleshooting ===
# Troubleshooting Commands
# kubectl exec my-pod -- ip addr # ดู Interface ทั้งหมด
# kubectl exec my-pod -- ip route # ดู Routing Table
# kubectl exec my-pod -- ping 10.10.0.100 # ทดสอบ Connectivity
# kubectl describe net-attach-def storage-net # ดู Network Config
# kubectl get net-attach-def -A # ดู Network ทั้งหมด
# journalctl -u kubelet | grep multus # ดู Multus Log
@dataclass
class MonitorItem:
metric: str
check_command: str
target: str
alert: str
monitoring = [
MonitorItem("Pod Network Interfaces",
"kubectl exec pod -- ip addr | grep net",
"ทุก Pod มี Interface ครบตาม Annotation",
"Missing Interface → P1 Check Multus CNI Log"),
MonitorItem("IP Address Pool Usage",
"kubectl get ippools (whereabouts)",
"< 80% ของ Subnet ที่จัด",
"> 90% → P2 Expand Subnet หรือ Cleanup"),
MonitorItem("Network Connectivity",
"kubectl exec pod -- ping ",
"RTT < 1ms (Same Node) < 5ms (Cross-node)",
"Timeout → P1 Check Host Interface CNI Config"),
MonitorItem("Bandwidth per Network",
"iperf3 between Pods on each network",
"Storage > 10Gbps | Mgmt > 1Gbps",
"< 50% expected → P2 Check MTU Congestion"),
MonitorItem("Multus DaemonSet Health",
"kubectl get ds -n kube-system multus",
"Running on all nodes READY = DESIRED",
"Not Ready → P1 Node ไม่มี Multi-network"),
]
print("=== Production Monitoring ===")
for m in monitoring:
print(f" [{m.metric}]")
print(f" Check: {m.check_command}")
print(f" Target: {m.target}")
print(f" Alert: {m.alert}")
เคล็ดลับ
- whereabouts: ใช้ whereabouts IPAM สำหรับ Multi-node IP Management
- Config: ไม่ Hardcode IP ใช้ ConfigMap/Env ตาม 12-Factor
- SR-IOV: ใช้ SR-IOV สำหรับ Performance-critical Network (NFV)
- Subnet: วางแผน Subnet ไม่ให้ชนกัน ใหญ่พอสำหรับ Scale
- Network Policy: ใช้ Network Policy แยก Traffic ตาม Security Zone
Multus CNI คืออะไร
Meta CNI Plugin Kubernetes Multi-Network Pod Interface macvlan ipvlan SR-IOV bridge NetworkAttachmentDefinition Storage Management NFV
12-Factor App คืออะไร
Methodology SaaS Codebase Dependencies Config Backing Services Build Processes Port Concurrency Disposability Parity Logs Admin
Configuration ทำอย่างไร
NetworkAttachmentDefinition YAML macvlan SR-IOV whereabouts IPAM Pod Annotation ConfigMap Env Variable DNS Service Discovery
Production Best Practices มีอะไร
Subnet Planning IPAM whereabouts Network Policy Security Zone SR-IOV Monitoring IP Pool Bandwidth DaemonSet Troubleshoot kubectl ip addr
สรุป
Multus CNI 12 Factor App Kubernetes Multi-Network macvlan SR-IOV whereabouts ConfigMap Env Stateless Scale Monitoring Production
