K8S 性能优化 - OS sysctl 调优
创始人
2024-06-02 10:22:30
0

前言

K8S 性能优化系列文章,本文为第一篇:OS sysctl 性能优化参数最佳实践。

参数一览

sysctl 调优参数一览

# Kubernetes Settings
vm.max_map_count = 262144
kernel.softlockup_panic = 1
kernel.softlockup_all_cpu_backtrace = 1
net.ipv4.ip_local_reserved_ports = 30000-32767# Increase the number of connections
net.core.somaxconn = 32768# Maximum Socket Receive Buffer
net.core.rmem_max = 16777216# Maximum Socket Send Buffer
net.core.wmem_max = 16777216# Increase the maximum total buffer-space allocatable
net.ipv4.tcp_wmem = 4096 87380 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216# Increase the number of outstanding syn requests allowed
net.ipv4.tcp_max_syn_backlog = 8096# For persistent HTTP connections
net.ipv4.tcp_slow_start_after_idle = 0# Allow to reuse TIME_WAIT sockets for new connections
# when it is safe from protocol viewpoint
net.ipv4.tcp_tw_reuse = 1# Max number of packets that can be queued on interface input
# If kernel is receiving packets faster than can be processed
# this queue increases
net.core.netdev_max_backlog = 16384# Increase size of file handles and inode cache
fs.file-max = 2097152# Max number of inotify instances and watches for a user
# Since dockerd runs as a single user, the default instances value of 128 per user is too low
# e.g. uses of inotify: nginx ingress controller, kubectl logs -f
fs.inotify.max_user_instances = 8192
fs.inotify.max_user_watches = 524288# Additional sysctl flags that kubelet expects
vm.overcommit_memory = 1
kernel.panic = 10
kernel.panic_on_oops = 1# Prevent docker from changing iptables: https://github.com/kubernetes/kubernetes/issues/40182
net.ipv4.ip_forward=1

如果是 AWS,额外增加如下:

# AWS settings
# Issue #23395
net.ipv4.neigh.default.gc_thresh1=0

如果启用了 IPv6,额外增加如下:

# Enable IPv6 forwarding for network plugins that don't do it themselves
net.ipv6.conf.all.forwarding=1

参数解释

分类内核参数说明参考链接
Kubernetesvm.max_map_count = 262144限制一个进程可以拥有的VMA(虚拟内存区域)的数量,
一个更大的值对于 elasticsearch、mongo 或其他 mmap 用户来说非常有用
ES Configuration
Kuberneteskernel.softlockup_panic = 1用于解决 K8S 内核软锁相关 bugroot cause kernel soft lockups · Issue #37853 · kubernetes/kubernetes (github.com)
Kuberneteskernel.softlockup_all_cpu_backtrace = 1用于解决 K8S 内核软锁相关 bugroot cause kernel soft lockups · Issue #37853 · kubernetes/kubernetes (github.com)
Kubernetesnet.ipv4.ip_local_reserved_ports = 30000-32767默认 K8S Nodport 端口service-node-port-range and ip_local_port_range collision · Issue #6342 · kubernetes/kops (github.com)
网络net.core.somaxconn = 32768表示socket监听(listen)的backlog上限。什么是backlog?backlog就是socket的监听队列,当一个请求(request)尚未被处理或建立时,他会进入backlog。
增加连接数.
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.core.rmem_max = 16777216接收套接字缓冲区大小的最大值(以字节为单位)。
最大化 Socket Receive Buffer
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.core.wmem_max = 16777216发送套接字缓冲区大小的最大值(以字节为单位)。
最大化 Socket Send Buffer
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.ipv4.tcp_wmem = 4096 87380 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
增加总的可分配的 buffer 空间的最大值Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.ipv4.tcp_max_syn_backlog = 8096表示那些尚未收到客户端确认信息的连接(SYN消息)队列的长度,默认为1024
增加未完成的syn请求的数量
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.ipv4.tcp_slow_start_after_idle = 0持久化 HTTP 连接Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.ipv4.tcp_tw_reuse = 1表示允许重用TIME_WAIT状态的套接字用于新的TCP连接,默认为0,表示关闭。
允许在协议安全的情况下重用TIME_WAIT 套接字用于新的连接
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.core.netdev_max_backlog = 16384当网卡接收数据包的速度大于内核处理的速度时,会有一个队列保存这些数据包。这个参数表示该队列的最大值
如果内核接收数据包的速度超过了可以处理的速度,这个队列就会增加
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
文件系统fs.file-max = 2097152该参数决定了系统中所允许的文件句柄最大数目,文件句柄设置代表linux系统中可以打开的文件的数量。
增加文件句柄和inode缓存的大小
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
文件系统fs.inotify.max_user_instances = 8192
fs.inotify.max_user_watches = 524288
一个用户的inotify实例和watch的最大数量
由于dockerd作为单个用户运行,每个用户的默认实例值128太低了
例如使用inotify: nginx ingress controller, kubectl logs -f
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
kubeletvm.overcommit_memory = 1对内存分配的一种策略
=1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
kubeletkernel.panic = 10panic错误中自动重启,等待时间为10秒Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
kubeletkernel.panic_on_oops = 1在Oops发生时会进行panic()操作Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
网络net.ipv4.ip_forward=1启用ip转发
另外也防止docker改变iptables
Upgrading docker 1.13 on nodes causes outbound container traffic to stop working · Issue #40182 · kubernetes/kubernetes (github.com)
网络net.ipv4.neigh.default.gc_thresh1=0修复 AWS arp_cache: neighbor table overflow! 报错arp_cache: neighbor table overflow! · Issue #4533 · kubernetes/kops (github.com)

EOF

三人行, 必有我师; 知识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.

相关内容

热门资讯

评书童林传250回的和300回... 评书童林传250回的和300回的有什么不一样?内容上是完全一样的,只是在剪辑时语速有所不同。 ...
为啥 有声小说凡人修仙传 和 ... 为啥 有声小说凡人修仙传 和 修真世界 很久都不更新了呢? 播音大灰狼去干吗了?凡人修仙传 和 修真...
月宫的主人不是嫦娥,你知道《封... 月宫的主人不是嫦娥,你知道《封神榜》中姜子牙封了谁吗?大家口中所说的嫦娥在历史上,其实并不是一个人,...
华软科技涨1.15%,成交额6... 7月1日,华软科技盘中上涨1.15%,截至09:57,报6.17元/股,成交6068.05万元,换手...
时间久了是不是真的会忘记? 时间久了是不是真的会忘记?如果那时是真的伤到了心,是不会忘记的,只会淡化,再久的时间想起来还是会有一...
菲沃泰涨1.21%,成交额66... 7月1日,菲沃泰盘中上涨1.21%,截至09:58,报16.76元/股,成交662.09万元,换手率...
党员总数超28.77万名 基层... 来源:本站原创  安庆市委组织部最新党内统计数据显示,截至2024年底,安庆市共有中国共产党党员28...
三棵树成立新材料科技子公司 转自:证券时报人民财讯7月1日电,企查查APP显示,近日,三棵树(海南)新材料科技有限公司成立,注册...
正海生物涨1.07%,成交额9... 7月1日,正海生物盘中上涨1.07%,截至09:43,报20.72元/股,成交936.02万元,换手...
奥联电子跌1.01%,成交额1... 7月1日,奥联电子(维权)盘中下跌1.01%,截至09:44,报15.69元/股,成交1018.39...