Kubernetes在Ubuntu上的扩展性实践
一 扩展路径总览
二 节点层面扩容步骤
sudo swapoff -a 并注释 /etc/fstab 中的 swap 行。net.bridge.bridge-nf-call-iptables=1、net.ipv4.ip_forward=1 等。sudo apt update && sudo apt install -y kubelet kubeadm kubectl && sudo apt-mark hold kubelet kubeadm kubectl。kubeadm token create --print-join-command,在目标节点执行输出的 kubeadm join ...。kubectl get nodes 应看到新节点状态为 Ready。kubectl label nodes <node-name> node-role.kubernetes.io/worker=。kubectl taint nodes <node-name> node-role.kubernetes.io/control-plane:NoSchedule。kubectl cordon <node>kubectl drain <node> --ignore-daemonsets --delete-emptydir-datakubectl delete node <node>三 工作负载层面扩展
kubectl scale deployment/<name> --replicas=<N>;有状态集:kubectl scale sts/<name> --replicas=<N>。apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: app
minReplicas: 2
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
--horizontal-pod-autoscaler-downscale-stabilization),并结合 QPS/延迟 等自定义指标。四 生产环境最佳实践与容量规划
--control-plane-endpoint 与 --upload-certs 构建 多控制平面 与 VIP/负载均衡,提升控制面可用性与横向扩展能力。