容器服务 ingress-nginx 应用部署指南

本指南将详细介绍如何在腾讯云容器服务 TKE 控制台的应用市场中部署社区版 ingress-nginx,并提供其关键参数的配置方法。

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

注意:ingress-nginx 应用基于开源的 ingress-nginx 构建,腾讯云容器服务不提供 SLA 保障。

一、通过控制台创建应用

1. 登录 容器服务控制台,选择左侧导航栏中的 运维中心 > 应用市场。

2. 在应用管理页面上方,选择需创建应用的集群及地域,并单击新建。

3. 在新建应用页面,选择 nginx-ingress 应用。如下:

4. 选择 Chart 版本,推荐版本如下:

Chart 版本 ingress-nginx 应用版本 推荐的 TKE 版本
4.2.5 v1.3.1 1.20,1.22,1.24
4.9.0 v1.9.5 1.26,1.28,1.30

5. 单击参数 Values.yaml ,进入参数配置界面,按需调整相关参数。

二、工作负载类型

支持以下两种工作负载类型:

·Deployment(默认)

·Daemonset

controller: # — Use a `DaemonSet` or `Deployment` kind: Deployment

三、资源设置

通过设置 requests 和 limits 为 ingress-nginx 分配资源。

controller: resources: ## limits: ## cpu: 100m ## memory: 90Mi requests: cpu: 100m memory: 90Mi

四、ingressClass 设置

默认的 ingressClass 为 nginx,可以通过设置不同值实现多个 ingress-nginx 应用的部署。

controller: … ingressClass: prod ingressClassResource: name: prod controllerValue: k8s.io/ingress-prod

在创建 Ingress 资源时,需要显式指定对应的 ingressClassName。

apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: nginxspec: ingressClassName: prod rules: – http: paths: – path: / pathType: Prefix backend: service: name: example port: number: 80

五、调度设置

支持以下调度方式:

·nodeSelector

·tolerations(容忍)

·affinity(亲和性)

示例配置如下:

controller: # nodeSelector nodeSelector: kubernetes.io/os: linux tolerations: [] # – key: "key" # operator: "Equal|Exists" # value: "value" # effect: "NoSchedule|PreferNoSchedule|NoExecute(1.6 only)" affinity: {} # # An example of preferred pod anti-affinity, weight is in the range 1-100 # podAntiAffinity: # preferredDuringSchedulingIgnoredDuringExecution: # – weight: 100 # podAffinityTerm: # labelSelector: # matchExpressions: # – key: app.kubernetes.io/name # operator: In # values: # – '{{ include "ingress-nginx.name" . }}' # – key: app.kubernetes.io/instance # operator: In # values: # – '{{ .Release.Name }}' # – key: app.kubernetes.io/component # operator: In # values: # – controller # topologyKey: kubernetes.io/hostname # # An example of required pod anti-affinity # podAntiAffinity: # requiredDuringSchedulingIgnoredDuringExecution: # – labelSelector: # matchExpressions: # – key: app.kubernetes.io/name # operator: In # values: # – '{{ include "ingress-nginx.name" . }}' # – key: app.kubernetes.io/instance # operator: In # values: # – '{{ .Release.Name }}' # – key: app.kubernetes.io/component # operator: In # values: # – controller # topologyKey: kubernetes.io/hostname

六、公网入口

请注意,启用公网入口会创建公网 CLB 资源。

controller: … service: enabled: true external: enabled: true annotations: service.cloud.tencent.com/direct-access: "true" # 开启直连 Pod 模式 service.cloud.tencent.com/enable-grace-shutdown: "true" # 表示使用优雅停机 service.cloud.tencent.com/enable-grace-shutdown-tkex: "true" type: LoadBalancer

七、内网入口

请注意,启用内网入口会创建内网 CLB 资源。

controller: … service: … internal: enabled: true annotations: service.cloud.tencent.com/direct-access: "true" # 开启直连 Pod 模式 service.cloud.tencent.com/enable-grace-shutdown: "true" # 表示使用优雅停机 service.cloud.tencent.com/prevent-loopback: "true" # 规避回环 service.cloud.tencent.com/enable-grace-shutdown-tkex: "true" service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: "subnet-xxx" # VPC 子网 ID type: "LoadBalancer"

注意:说明:

注意:如果希望使用已有的 CLB,可以通过如下注解实现:service.kubernetes.io/tke-existed-lbid: <LoadBalanceId>。更多关于 Service 的配置信息,请参见 Service 使用已有 CLB。

八、弹性伸缩 HPA

通过 Deployment 工作负载类型部署时,可以配置以下弹性伸缩策略。

controller: … autoscaling: enabled: true annotations: {} minReplicas: 1 maxReplicas: 11 targetCPUUtilizationPercentage: 50 targetMemoryUtilizationPercentage: 50 behavior: {} # scaleDown: # stabilizationWindowSeconds: 300 # policies: # – type: Pods # value: 1 # periodSeconds: 180 # scaleUp: # stabilizationWindowSeconds: 300 # policies: # – type: Pods # value: 2 # periodSeconds: 60

TKE 还支持基于自定义指标的弹性伸缩,示例如下。更多 TKE 支持的自定义指标请参见 自动伸缩指标说明。

controller: … autoscalingTemplate: – pods: metric: name: k8s_pod_rate_cpu_core_used_limit target: averageValue: "80" type: AverageValue type: Pods

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