如果您想在部署 nginx-ingress-controller 时提供自己的配置,您可以在原始 nginx-ingress Helm 图表上创建一个包装 Helm 图表,并提供您自己的 values.yaml 可以进行自定义配置。
在这里使用 Helm 3。
创建图表:
$ helm create custom-nginx
$ tree custom-nginx
所以我的图表结构是这样的:
custom-nginx/
├── Chart.yaml
├── charts
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── service.yaml
│ ├── serviceaccount.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
这里还有一些额外的东西。具体来说,我不需要完整的 templates/ 目录及其内容,因此我将删除这些内容:
$ rm custom-nginx/templates/*
$ rmdir custom-nginx/templates
现在,图表结构应如下所示:
custom-nginx/
├── Chart.yaml
├── charts
└── values.yaml
因为,我们必须将原始 nginx-ingress 图表作为依赖项包含在内,所以我的 Chart.yaml 看起来像这样:
$ cat custom-nginx/Chart.yaml
apiVersion: v2
name: custom-nginx
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.39.1
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.32.0
dependencies:
- name: nginx-ingress
version: 1.39.1
repository: https://kubernetes-charts.storage.googleapis.com/
这里,appVersion 是 nginx-controller docker 映像版本,version 与我正在使用的 nginx-ingress 图表版本匹配。
唯一剩下的就是提供您的自定义配置。这是我的自定义配置的精简版:
$ cat custom-nginx/values.yaml
# Default values for custom-nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
nginx-ingress:
controller:
ingressClass: internal-nginx
replicaCount: 1
service:
externalTrafficPolicy: Local
publishService:
enabled: true
autoscaling:
enabled: true
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: "80"
targetMemoryUtilizationPercentage: "80"
resources:
requests:
cpu: 1
memory: 2Gi
limits:
cpu: 1
memory : 2Gi
metrics:
enabled: true
config:
compute-full-forwarded-for: "true"
我们可以在https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/ 中检查可用作配置的密钥(values.yaml 中的config 部分)
其余的配置可以在这里找到:https://github.com/helm/charts/tree/master/stable/nginx-ingress#configuration
配置完成后,只需下载图表的依赖项:
$ helm dependency update <path/to/chart>
最好在部署图表之前对其进行基本检查:
$ helm lint <path/to/chart>
$ helm install --debug --dry-run --namespace <namespace> <release-name> <path/to/chart>
然后部署您的图表(它将使用您自己的自定义配置部署您的 nginx-ingress-controller)。
另外,既然你现在有一个图表,你可以升级和回滚你的图表。