容器服务 高可用配置优化

这篇说说Nginx Ingress的高可用部署配置,包括调高副本数(自动扩缩容或固定副本数)、打散调度以支持容灾、调度到专用节点以及合理设置资源request/limit。 调高副本数:支持HPA自动扩缩容(快速扩容、缓慢缩容)或固定replicaCount。 打散调度:使用topologySpreadConstraints按可用区和主机名打散Pod,避免单点故障。 调度专用节点:通过nodeSelector将Ngi。

相关产品
容器服务 产品页,含版本规格、价格与购买入口。

注意:ingress-nginx 是一个由社区维护的开源项目。这篇内容仅供参考,不提供支持。如在使用过程中遇到问题,建议查阅 ingress-nginx 社区 的最新产品文档以获取帮助。

一、概述

这篇说说 Nginx Ingress 的高可用部署配置方法。

二、调高副本数

配置自动扩缩容:

controller: autoscaling: enabled: true minReplicas: 10 maxReplicas: 100 targetCPUUtilizationPercentage: 50 targetMemoryUtilizationPercentage: 50 behavior: # 快速扩容应对流量洪峰,缓慢缩容预留 buffer 避免流量异常 scaleUp: stabilizationWindowSeconds: 300 policies: – type: Percent value: 900 periodSeconds: 15 # 每 15s 最多允许扩容 9 倍于当前副本数 scaleDown: stabilizationWindowSeconds: 300 policies: – type: Pods value: 1 periodSeconds: 600 # 每 10 分钟最多只允许缩掉 1 个 Pod

如果希望固定副本数,直接配置 replicaCount:

controller: replicaCount: 50

三、打散调度

使用拓扑分布约束将 Pod 打散以支持容灾,避免单点故障:

controller: topologySpreadConstraints: # 尽量打散的策略 – labelSelector: matchLabels: app.kubernetes.io/name: '{{ include "ingress-nginx.name" . }}' app.kubernetes.io/instance: '{{ .Release.Name }}' app.kubernetes.io/component: controller topologyKey: topology.kubernetes.io/zone maxSkew: 1 whenUnsatisfiable: ScheduleAnyway – labelSelector: matchLabels: app.kubernetes.io/name: '{{ include "ingress-nginx.name" . }}' app.kubernetes.io/instance: '{{ .Release.Name }}' app.kubernetes.io/component: controller topologyKey: kubernetes.io/hostname maxSkew: 1 whenUnsatisfiable: ScheduleAnyway

四、调度专用节点

通常 Nginx Ingress Controller 的负载跟流量成正比,由于 Nginx Ingress Controller 作为网关的重要性,可以考虑将其调度到专用的节点或者超级节点,避免干扰业务 Pod 或被业务 Pod 干扰。

调度到指定节点池:

controller: nodeSelector: tke.cloud.tencent.com/nodepool-id: np-********

注意:说明:

注意:超级节点的效果更好,所有 Pod 独占虚拟机,不会相互干扰。如果使用的是 Serverless 集群,则不需要配这里的调度策略,只会调度到超级节点。

五、合理设置 request limit

如果 Nginx Ingress 不是调度到超级节点,需合理设置 request 和 limit,既要确保有足够的资源,也要避免使用过多资源导致节点负载过高:

controller: resources: requests: cpu: 500m memory: 512Mi limits: cpu: 1000m memory: 1Gi

如果使用的是超级节点或 Serverless 集群,只需要定义 requests,即声明每个 Pod 的虚拟机规格:

controller: resources: requests: cpu: 1000m memory: 2Gi

赞 (0)
上一篇 4天前
下一篇 4天前