CentOS 上 Kubernetes 的容器编排策略
一 编排策略总览
二 发布与回滚策略
kubectl set image deployment/<name> <container>=<image:vX>kubectl rollout status deployment/<name>kubectl rollout undo deployment/<name>(可指定 --to-revision)三 扩缩容与弹性策略
kubectl scale deployment/<name> --replicas=<N>apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: app
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
四 调度与高可用策略
podAntiAffinity 将同一应用的副本分散到不同节点(按 kubernetes.io/hostname 拓扑)。kubectl taint nodes <node> key=value:NoSchedule;关键业务 Pod 配置相应 tolerations 以准入。affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values: [myapp]
topologyKey: "kubernetes.io/hostname"
resources:
requests:
cpu: "250m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
五 在 CentOS 上的落地要点
swapoff -a 并注释 /etc/fstab 中的 swap 行;禁用 SELinux 或设为 permissive;内核开启桥接流量到 iptables:modprobe br_netfilter
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
/etc/containerd/config.toml 中设置 SystemdCgroup = true,systemctl enable --now containerd。/etc/docker/daemon.json 设置 "exec-opts": ["native.cgroupdriver=systemd"]。kubeadm init --pod-network-cidr=10.244.0.0/16;kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml;kubeadm join ...;验证 kubectl get nodes 与 kubectl get pods -A。