教育-部署Kubernetes集群:优化kubernetes集群
时间:2025-02-12 14:52:59
优化kubernetes集群
- 关闭swap
ansible k8smaster -m shell -a "swapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab"
- 优化服务器内核参数
- 脚本
##优化内核参数,文件k8s.conf、limits.conf在部署文件夹内---- name: config sysctlhosts: k8stasks:- name: copy sysctl kernel arguscopy: src=/etc/ansible/k8s.conf dest=/etc/sysctl.d/- name:shell : sysctl --system- name: config limitcopy: src=/etc/ansible/limits.conf dest=/etc/security/limits.conf
- 执行
ansible-playbook sysctl_config.yaml
- 验证
ansible k8smaster -m shell -a "sysctl --system"
- 脚本
- 开启ip_vs模块
- 脚本
##k8s集群使用ip_VS模式,能大大提高性能,减少iptables规则数量---- name: start ipvs modulehosts: k8stasks:- name:shell : modprobe -- ip_vs && modprobe -- ip_vs_rr && modprobe -- ip_vs_wrr && modprobe -- ip_vs_sh && modprobe -- nf_conntrack_ipv4
- 执行脚本
ansible-playbook ipvs.yaml
- 验证
ansible k8s -m shell -a "lsmod | grep ip_vs"
图1 验证4Figure4:
- 脚本
support.huaweicloud.com/tsecp-education/tsecp_06.html