Ingress-nginx 部署手册 (Helm 版本)
1. 概述
本文档介绍如何使用 Helm 在 Kubernetes 集群中部署 Ingress-nginx服务。
2. 前提条件
- Kubernetes 集群 (v1.16+)
- Helm (v3.0+)
- 集群节点可访问公司内网
- 足够的 Kubernetes 操作权限
3. 部署步骤
3.1 创建Ingress-Nginx TLS Secret
创建 ingress-nginx-tls.yaml
文件,内容如下:
apiVersion: v1
kind: Secret
metadata:
name: default-cert-secret
namespace: ingress-nginx
type: kubernetes.io/tls
data:
tls.crt: 根据自己的证书设置
tls.key: 根据自己的证书设置
3.2 部署Ingress-Nginx TLS Secret
kubectl apply -f ingress-nginx-tls.yaml
3.3 添加 Helm 仓库
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
3.4 创建配置文件
创建 ingress-nginx-values.yaml
文件,内容如下:
# ingress-nginx-values.yaml
# 基本配置
global:
image:
# -- Registry host to pull images from.
registry: registry.cn-hangzhou.aliyuncs.com
controller:
name: controller
enableAnnotationValidations: true
replicaCount: 1
image:
## Keep false as default for now!
chroot: false
# registry: registry.k8s.io
image: google_containers/nginx-ingress-controller
tag: "v1.12.2"
digest: sha256:ba65ee572fa4a4ff36a366fd78d342d70c13ddd0c186b369b532628dd9b2fc50
pullPolicy: IfNotPresent
config:
# 全局请求体大小限制(对所有Ingress生效)
proxy-body-size: "2000m" # 2000MB,按需调整
ssl-protocols: "TLSv1.2 TLSv1.3" # 允许的协议版本
ssl-redirect: "false" # 启用自动跳转
force-ssl-redirect: "false" # 强制跳转
hsts: "false" # 禁用 HSTS 的配置
compute-full-forwarded-for: "true" # 将远程地址附加到 X-Forwarded-For 标头
use-forwarded-headers: "true" # 启用对 X-Forwarded-* 系列请求头的支持
forwarded-for-header: "X-Forwarded-For" # 指定用于传递客户端 IP 地址的请求头字段名称为 X-Forwarded-For
#1.默认禁用:从 Ingress-NGINX v1.12.0 开始,默认情况下禁用了nginx.ingress.kubernetes.io/configuration-snippet 注解,因为它们被认为可能包含高风险的配置。
#2.安全限制:为了防止恶意用户通过注解注入危险的配置,Ingress-NGINX 引入了更严格的安全检查
#allow-snippet-annotations: "true" #可以设置allowSnippetAnnotations: true
#annotations-risk-level: "Critical"
# 如果需要对特定Ingress生效,需启用注解
allowSnippetAnnotations: true # 允许使用注解覆盖全局配置
extraArgs:
default-ssl-certificate: "ingress-nginx/default-cert-secret" #配置默认证书
# TCP 服务配置映射(ConfigMap)设置
# -------------------------------
# 指定用于存储 TCP 代理规则的 ConfigMap 名称
# 格式: "<命名空间>/<configmap名称>"
# 示例:
# tcp-services-configmap: "ingress-nginx/custom-tcp-rules" # 使用指定命名空间的自定义 ConfigMap
# tcp-services-configmap: "ingress-nginx/ingress-nginx-tcp" # 使用默认生成的 nginx-tcp ConfigMap(推荐大多数情况)
# -- Use a `DaemonSet` or `Deployment`
kind: Deployment
service:
enabled: true
type: NodePort
nodePorts:
http: 80
https: 443
# TCP 端口映射配置
# -------------------------------
# 格式说明:
# "<外部暴露端口>: <NodePort端口>"
#
# 注意事项:
# 1. NodePort 范围默认为 30000-32767
# 2. 如需使用特权端口(<1024),需额外配置
#
# 示例(常规用法):
tcp:
# 6380: 6380 # 外部访问 6380 端口映射到 NodePort 6380
resources:
## limits:
## cpu: 100m
## memory: 90Mi
requests:
cpu: 500m
memory: 500Mi
admissionWebhooks:
patch:
enabled: true
image:
# registry: registry.k8s.io
image: google_containers/kube-webhook-certgen
## for backwards compatibility consider setting the full image url via the repository value below
## use *either* current default registry/image or repository format or installing chart by providing the values.yaml will fail
## repository:
tag: v1.5.3
digest: sha256:39c0f0694e12f7fef378ea2e8a5c4040cc95d10d45b3f201cad918f7475508bd
pullPolicy: IfNotPresent
# ====================== TCP/UDP 代理配置 ======================
# 默认情况下,ingress-nginx 仅开启 HTTP(80) 和 HTTPS(443) 端口代理
# 如需启用 TCP/UDP 代理(如 Redis、MySQL、Rabbitmq 等非 HTTP 服务),需取消下方注释并配置转发规则
#
# 配置格式说明:
# "<外部端口>": "<命名空间>/<服务名称>:<服务端口>"
#
# 注意事项:
# 1. 启用后会自动生成 nginx-tcp ConfigMap
#
# 示例:将外部 6380 端口代理到 redis-cluster 命名空间的 Redis proxy 服务
tcp:
# 6380: "redis-cluster/camellia-redis-cluster-proxy:6380"
# ====================== 端口暴露配置 ======================
3.5 部署 Ingress-nginx
执行以下命令部署 Ingress-nginx:
# 使用 Helm 部署
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx \
--create-namespace \
--values ingress-nginx-values.yaml \
--version 4.12.2
3.6 验证部署
执行以下命令验证 CoreDNS 部署状态:
1. 检查 Pod 状态
# 检查 Pod 状态
kubectl get pods -n ingress-nginx -o wide
# 检查服务状态
kubectl get svc -n ingress-nginx
4.0 注意事项
- k8s默认service端口是30000-32767,因使用NodePort绑定80/443端口,所以需要修改端口范围