在CentOS上优化Kubernetes(K8s)部署可以从多个方面入手,包括系统初始化、软件安装、网络配置和资源管理等。以下是一些详细的优化策略:
/etc/sysctl.d/k8s.conf
文件,优化内核参数,例如:net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=1048576
fs.file-max=2097152
fs.nr_open=2097152
net.netfilter.nf_conntrack_max=2310720
net.ipv4.tcp_keepalive_time=600
net.ipv4.tcp_keepalive_probes=3
net.ipv4.tcp_keepalive_intvl=15
net.ipv4.tcp_max_tw_buckets=36000
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_max_orphans=327680
net.ipv4.tcp_orphan_retries=3
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_max_syn_backlog=16384
net.ipv4.ip_local_reserved_ports=1024-65535
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.core.somaxconn=32768
执行 sysctl -p /etc/sysctl.d/k8s.conf
使配置生效。yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
systemctl enable docker && systemctl start docker
关闭SELinux:sudo setenforce 0
sudo sed -i --follow-symlinks 's/SELINUXenforcing/SELINUXdisabled/' /etc/selinux/config
配置主机名和hosts文件:hostnamectl set-hostname hostname
cat >> /etc/hosts << eof
192.168.2.190 k8s-master
192.168.2.126 k8s-node1
192.168.2.135 k8s-node2
eof
通过上述优化措施,可以显著提升CentOS上Kubernetes集群的性能和稳定性。具体的配置参数可能需要根据实际的集群规模、网络环境和性能需求进行调整。