教育-部署Kubernetes集群:优化kubernetes集群

时间:2024-05-10 10:33:51

优化kubernetes集群

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