K8S 性能优化 - OS sysctl 调优

简介: K8S 性能优化 - OS sysctl 调优

前言

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
INI

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

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

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

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

参数解释

分类 内核参数 说明 参考链接
Kubernetes vm.max_map_count = 262144 限制一个进程可以拥有的 VMA(虚拟内存区域)的数量,
一个更大的值对于 elasticsearch、mongo 或其他 mmap 用户来说非常有用
ES Configuration
Kubernetes kernel.softlockup_panic = 1 用于解决 K8S 内核软锁相关 bug root cause kernel soft lockups · Issue #37853 · kubernetes/kubernetes (github.com)
Kubernetes kernel.softlockup_all_cpu_backtrace = 1 用于解决 K8S 内核软锁相关 bug root cause kernel soft lockups · Issue #37853 · kubernetes/kubernetes (github.com)
Kubernetes net.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)
kubelet vm.overcommit_memory = 1 对内存分配的一种策略
=1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何
Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
kubelet kernel.panic = 10 panic 错误中自动重启,等待时间为 10 秒 Image: We should tweak our sysctls · Issue #261 · kubernetes-retired/kube-deploy (github.com)
kubelet kernel.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

相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
4天前
|
运维 Kubernetes 监控
Kubernetes 集群的持续性能优化实践
【4月更文挑战第26天】 在动态且不断增长的云计算环境中,维护高性能的 Kubernetes 集群是一个挑战。本文将探讨一系列实用的策略和工具,旨在帮助运维专家监控、分析和优化 Kubernetes 集群的性能。我们将讨论资源分配的最佳实践,包括 CPU 和内存管理,以及集群规模调整的策略。此外,文中还将介绍延迟和吞吐量的重要性,并提供日志和监控工具的使用技巧,以实现持续改进的目标。
|
8天前
|
存储 运维 Kubernetes
Kubernetes 集群的持续性能优化实践
【4月更文挑战第22天】在动态且复杂的微服务架构中,确保 Kubernetes 集群的高性能运行是至关重要的。本文将深入探讨针对 Kubernetes 集群性能优化的策略与实践,从节点资源配置、网络优化到应用部署模式等多个维度展开,旨在为运维工程师提供一套系统的性能调优方法论。通过实际案例分析与经验总结,读者可以掌握持续优化 Kubernetes 集群性能的有效手段,以适应不断变化的业务需求和技术挑战。
|
21天前
|
监控 Unix Linux
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
32 0
|
3月前
|
缓存 Kubernetes API
K8S 性能优化 - K8S APIServer 调优
K8S 性能优化 - K8S APIServer 调优
|
3月前
|
Kubernetes 调度 容器
K8S 性能优化 -K8S Node 参数调优
K8S 性能优化 -K8S Node 参数调优
|
21天前
|
Linux
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
22 0
|
3月前
|
Kubernetes 容器 Perl
K8S 性能优化 - 大型集群 CIDR 配置
K8S 性能优化 - 大型集群 CIDR 配置
|
5月前
|
存储 Kubernetes Cloud Native
云原生|kubernetes|etcd集群详细介绍+安装部署+调优
云原生|kubernetes|etcd集群详细介绍+安装部署+调优
250 0
|
9月前
|
人工智能 并行计算 Cloud Native
关于 ANCE OS 兼容性评估 & Linux 智能全栈调优 KeenTune 介绍 | 第 93-94 期
了解兼容性评估工具核心特性、基本工作原理和使用方法及熟悉 Linux 全栈性能调优。
关于 ANCE OS 兼容性评估 & Linux 智能全栈调优 KeenTune 介绍 | 第 93-94 期
|
存储 Kubernetes Cloud Native
云原生|kubernetes|etcd集群详细介绍+安装部署+调优(二)
云原生|kubernetes|etcd集群详细介绍+安装部署+调优
917 0

推荐镜像

更多