k8s nginx-ingress上的配置优化
2021/7/5 7:21:21
本文主要是介绍k8s nginx-ingress上的配置优化,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
自建K8s上,如果部署了Nginx-Ingress,通常一些默认的参数有些可能需要优化下以便提升它的性能(阿里云之类的云厂商提供的Ingress是优化过的)。
我下面是自建的测试K8s上部署的ingress,这里贴下优化的地方:
kubectl get cm -n ingress-nginx
NAME DATA AGE ingress-controller-leader-nginx 0 6d19h ingress-nginx-controller 0 6d19h nginx-ingress-controller 22 5d20h
1、修改些nginx的常用参数
kubectl get cm -n ingress-nginx nginx-ingress-controller -oyaml 下面是data的内容,部分可以再根据实际情况修改(例如日志文件的路径)
apiVersion: v1 data: access-log-path: /var/log/nginx/access.log disable-access-log: "false" disable-ipv6: "true" disable-ipv6-dns: "true" enable-modsecurity: "false" enable-multi-accept: "true" enable-opentracing: "true" error-log-level: notice error-log-path: /var/log/nginx/error.log generate-request-id: "true" keep-alive: "60" keep-alive-requests: "10000" load-balance: round_robin log-format-escape-json: "true" max-worker-connections: "65535" max-worker-open-files: "10240" nginx-status-ipv4-whitelist: 0.0.0.0 reuse-port: "true" upstream-keepalive-connections: "200" upstream-keepalive-requests: "100" upstream-keepalive-timeout: "60" worker-processes: "4" kind: ConfigMap .... 其余部分忽略....
2、修改下nginx容器的内核参数
kubectl get deployments -n ingress-nginx -oyaml 注意这里加了个initContainers的配置,主要是修改一些内核参数,更适配Nginx的使用场景
dnsPolicy: ClusterFirst initContainers: - command: - /bin/sh - -c - | mount -o remount rw /proc/sys sysctl -w net.core.somaxconn=65535 sysctl -w net.ipv4.tcp_tw_reuse=1 sysctl -w net.ipv4.ip_local_port_range="1024 65535" sysctl -w fs.file-max=1048576 sysctl -w fs.inotify.max_user_instances=16384 sysctl -w fs.inotify.max_user_watches=524288 sysctl -w fs.inotify.max_queued_events=16384 image: busybox imagePullPolicy: IfNotPresent name: init-sysctl resources: {} securityContext: capabilities: add: - SYS_ADMIN drop: - ALL terminationMessagePath: /dev/termination-log terminationMessagePolicy: File nodeSelector: kubernetes.io/os: linux restartPolicy: Always schedulerName: default-scheduler
参考:
https://zhuanlan.zhihu.com/p/212620792 https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/ https://www.nginx.com/blog/tuning-nginx/ https://mp.weixin.qq.com/s/NAwz4dlsPuJnqfWYBHkfGg
这篇关于k8s nginx-ingress上的配置优化的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-2610 个你不知道自己需要的 Kubernetes 工具
- 2024-09-25MicroK8s 概览 — 使用一条命令部署自己的 Kubernetes 集群
- 2024-08-19云原生周刊:Kubernetes v1.31 发布
- 2024-08-13探索 Kubernetes 持久化存储之 Rook Ceph 初窥门径
- 2024-07-25探索 Kubernetes 持久化存储之 Longhorn 初窥门径
- 2024-07-23云原生周刊:Kubernetes v1.31 中的移除和主要变更|2024.7.22
- 2024-07-22Kubernetes 持久化存储之 NFS 终极实战指南
- 2024-07-15云原生周刊:Argo Rollouts 支持 Kubernetes Gateway API 1.0 | 2024.7.1
- 2024-07-15云原生周刊:一条 Kubernetes 命令引发的悲剧
- 2024-07-15K8s GPU 资源管理探索:在 KubeSphere 上部署 AI 大模型 Ollama