Overview
Nginx Ingress Controller is a Kubernetes Ingress controller based on the high-performance NGINX reverse proxy, and it is also one of the most commonly used open-source Ingress implementations. This document explains how to self-build an Nginx Ingress Controller in the TKE environment, mainly using helm for installation and providing some values.yaml
configuration guidance. Prerequisites
A TKE cluster is created.
The TKE cluster's kubeconfig is configured, with the permissions to operate the TKE cluster. For more details, see connect to the cluster. Installation with helm
Add helm repo:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
View default configuration:
helm show values ingress-nginx/ingress-nginx
The Nginx Ingress dependent image is under the registry.k8s.io
registry. In the network environment in Chinese mainland, it cannot be pulled. You can replace it with the mirror image in docker hub.
Prepare values.yaml
:
controller:
image:
registry: docker.io
image: k8smirror/ingress-nginx-controller
admissionWebhooks:
patch:
image:
registry: docker.io
image: k8smirror/ingress-nginx-kube-webhook-certgen
defaultBackend:
image:
registry: docker.io
image: k8smirror/defaultbackend-amd64
opentelemetry:
image:
registry: docker.io
image: k8smirror/ingress-nginx-opentelemetry
Note:
All mirror images in the configuration use image-porter for long-term automatic synchronization, so you can perform installation and upgrade with confidence. Installation:
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \\
--namespace ingress-nginx --create-namespace \\
-f values.yaml
Note:
If you need to modify the values configuration or upgrade the version in the future, you can update Nginx Ingress Controller by running this command.
Check the traffic entry (CLB VIP or domain name):
$ kubectl get services -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer xxx.xx.xxx.xxx xxx.xx.xx.xxx 80:30683/TCP,443:32111/TCP 53s
ingress-nginx-controller-admission ClusterIP xxx.xx.xxx.xxx <none> 443/TCP 53s
Note:
EXTERNAL-IP
of a LoadBalancer
service is the VIP or domain name of the CLB. You can configure DNS resolution for it. If it is a VIP, configure an A record; if it is a CLB domain name, configure a CNAME record.
Versions and Upgrades
The version of Nginx Ingress needs to be compatible with the Kubernetes cluster version. Refer to the official Supported Versions table to confirm if the current cluster version supports the latest Nginx Ingress. If not, you need to specify the chart version during installation. For example, if the current TKE cluster version is 1.24, the latest chart version can only be 4.7.*
. Run the following commands to check available versions:
$ helm search repo ingress-nginx/ingress-nginx --versions | grep 4.7.
ingress-nginx/ingress-nginx 4.7.5 1.8.5 Ingress controller for Kubernetes using NGINX a...
ingress-nginx/ingress-nginx 4.7.3 1.8.4 Ingress controller for Kubernetes using NGINX a...
ingress-nginx/ingress-nginx 4.7.2 1.8.2 Ingress controller for Kubernetes using NGINX a...
ingress-nginx/ingress-nginx 4.7.1 1.8.1 Ingress controller for Kubernetes using NGINX a...
ingress-nginx/ingress-nginx 4.7.0 1.8.0 Ingress controller for Kubernetes using NGINX a...
You can see that the latest 4.7.*
version is 4.7.5
. Add the version number during installation:
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \\
--version 4.7.5 \\
--namespace ingress-nginx --create-namespace \\
-f values.yaml
Note:
Before upgrading the TKE cluster, check if the current Nginx Ingress version is compatible with the upgraded cluster version. If not, upgrade Nginx Ingress first (run the preceding command to specify the chart version).
Using Ingress
Nginx Ingress implements the standard capabilities of Kubernetes's Ingress API definition. For basic usage of Ingress, refer to the Kubernetes official documentation. You must specify ingressClassName
as IngressClass (nginx
by default) used by the Nginx Ingress instance:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
Additionally, Nginx Ingress has many other unique features. For details on extending the features of Ingress through Ingress annotations, refer to Nginx Ingress Annotations. More Customization
If you need more customization for Nginx Ingress, refer to the following document and merge the values.yaml
configuration as needed. The Complete Example of values.yaml Configuration provides a complete example of values.yaml
configuration after merging.
Was this page helpful?