Help Center> Cloud Container Engine> User Guide> Add-ons> Nginx Ingress Controller
Updated on 2024-03-11 GMT+08:00

Nginx Ingress Controller

Introduction

Kubernetes uses kube-proxy to expose Services and provide load balancing. The implementation is at the transport layer. When it comes to Internet applications, where a bucket-load of information is generated, forwarding needs to be more fine-grained, precisely and flexibly controlled by policies and load balancers to deliver higher performance.

This is where ingresses enter. Ingresses provide application-layer forwarding functions, such as virtual hosts, load balancing, SSL proxy, and HTTP routing, for Services that can be directly accessed outside a cluster.

Kubernetes has officially released the Nginx-based Ingress controller. CCE Nginx Ingress controller directly uses community templates and images. The Nginx Ingress controller generates Nginx configuration and stores the configuration using ConfigMap. The configuration will be written to Nginx pods through the Kubernetes API. In this way, the Nginx configuration is modified and updated. For details, see How nginx-ingress Works.

You can visit the open source community for more information.

  • When installing the add-on, you can add configurations by defining the Nginx configuration. The configurations take effect globally. This parameter is generated by configuring the nginx.conf file and affects all managed ingresses. You can search for related parameters in the ConfigMaps. If the configured parameters are not included in the options listed in the ConfigMaps, the configurations do not take effect.
  • After the add-on is installed, you can interconnect with Nginx and set Nginx ingress functions using Annotationswhen creating an ingress on the CCE console. For details about the supported annotation fields, see Annotations.
  • Do not manually modify or delete the load balancer and listener that are automatically created by CCE. Otherwise, the workload will be abnormal. If you have modified or deleted them by mistake, uninstall the nginx-ingress add-on and re-install it.

How nginx-ingress Works

nginx-ingress consists of the ingress object, ingress controller, and Nginx. The ingress controller assembles ingresses into the Nginx configuration file (nginx.conf) and reloads Nginx to make the changed configurations take effect. When it detects that the pod in a Service changes, it dynamically changes the upstream server group configuration of Nginx. In this case, the Nginx process does not need to be reloaded. Figure 1 shows how nginx-ingress works.

  • An ingress is a group of access rules that forward requests to specified Services based on domain names or URLs. Ingresses are stored in the object storage service etcd and are added, deleted, modified, and queried through APIs.
  • The ingress controller monitors the changes of resource objects such as ingresses, Services, endpoints, secrets (mainly TLS certificates and keys), nodes, and ConfigMaps in real time and automatically performs operations on Nginx.
  • Nginx implements load balancing and access control at the application layer.
Figure 1 Working principles of nginx-ingress

Constraints

  • This add-on can be installed only in clusters of v1.15 or later.
  • For clusters earlier than v1.23, kubernetes.io/ingress.class: "nginx" must be added to the annotation of the Ingress created through the API.
  • Dedicated load balancers must be the network type (TCP/UDP) supporting private networks (with a private IP).
  • The node where nginx-ingress-controller is running and the containers running on the node cannot access Nginx Ingress. In this case, perform anti-affinity deployment for the workloads and nginx-ingress-controller. For details, see Anti-affinity Deployment for Workloads and nginx-ingress-controller.
  • During the nginx-ingress upgrade, 10s is reserved for deleting the nginx-ingress controller at the ELB backend.
  • The timeout interval for the graceful exit of nginx-ingress-controller is 300s. If the timeout is more than 300s during the nginx-ingress upgrade, the persistent connection will be disconnected and services will be interrupted for a short period of time.

Prerequisites

Before creating a workload, you must have an available cluster. If no cluster is available, create one according to Buying a CCE Cluster.

Installing the Add-on

  1. Log in to the CCE console and click the cluster name to access the cluster console. Choose Add-ons in the navigation pane, locate NGINX Ingress Controller on the right, and click Install.
  2. On the Install Add-on page, configure the specifications.

    Table 1 nginx-ingress configuration

    Parameter

    Description

    Add-on Specifications

    Nginx Ingress can be deployed based on customized resource specifications.

    Instances

    You can adjust the number of add-on instances as required.

    Containers

    You can adjust the container specifications of an add-on instance as required.

  3. Configure the add-on parameters.

    • Load Balancer: Select a shared or dedicated load balancer. If no load balancer is available, create one. The load balancer has at least two listeners, and ports 80 and 443 are not occupied by listeners.
    • Admission Verification: Admission control is performed on Ingresses to ensure that the controller can generate valid configurations. Admission verification is performed on the configuration of Nginx Ingresses. If the verification fails, the request will be intercepted. For details about admission verification, see Access Control.
      • Admission check slows down the responses to Ingress requests.
      • Only add-ons of version 2.4.1 or later support admission verification.
    • Nginx Parameters: Configuring the nginx.conf file will affect all managed ingresses. You can search for related parameters through ConfigMaps. If the parameters you configured are not included in the options listed in the ConfigMaps, the parameters will not take effect.

      For example, you can use the keep-alive-requests parameter to describe how to set the maximum number of requests for keeping active connections to 100.

      {
          "keep-alive-requests": "100"
      }
    • Default 404 Service: By default, the 404 service provided by the add-on is used. To customize the 404 service, enter the namespace/service name. If the service does not exist, the add-on installation will fail.

  4. Configure scheduling policies for the add-on.

    • Scheduling policies do not take effect on add-on instances of the DaemonSet type.
    • When configuring multi-AZ deployment or node affinity, ensure that there are nodes meeting the scheduling policy and that resources are sufficient in the cluster. Otherwise, the add-on cannot run.
    Table 2 Configurations for add-on scheduling

    Parameter

    Description

    Multi-AZ Deployment

    • Preferred: Deployment pods of the add-on will be preferentially scheduled to nodes in different AZs. If all the nodes in the cluster are deployed in the same AZ, the pods will be scheduled to that AZ.
    • Equivalent mode: Deployment pods of the add-on are evenly scheduled to the nodes in the cluster in each AZ. If a new AZ is added, you are advised to increase add-on pods for cross-AZ HA deployment. With the Equivalent multi-AZ deployment, the difference between the number of add-on pods in different AZs will be less than or equal to 1. If resources in one of the AZs are insufficient, pods cannot be scheduled to that AZ.
    • Forcible: Deployment pods of the add-on will be forcibly scheduled to nodes in different AZs. If there are fewer AZs than pods, the extra pods will fail to run.

    Node Affinity

    • Incompatibility: Node affinity is disabled for the add-on.
    • Node Affinity: Specify the nodes where the add-on is deployed. If you do not specify the nodes, the add-on will be randomly scheduled based on the default cluster scheduling policy.
    • Specified Node Pool Scheduling: Specify the node pool where the add-on is deployed. If you do not specify the node pool, the add-on will be randomly scheduled based on the default cluster scheduling policy.
    • Custom Policies: Enter the labels of the nodes where the add-on is to be deployed for more flexible scheduling policies. If you do not specify node labels, the add-on will be randomly scheduled based on the default cluster scheduling policy.

      If multiple custom affinity policies are configured, ensure that there are nodes that meet all the affinity policies in the cluster. Otherwise, the add-on cannot run.

    Taints and Tolerations

    Using both taints and tolerations allows (not forcibly) the add-on Deployment to be scheduled to a node with the matching taints, and controls the Deployment eviction policies after the node where the Deployment is located is tainted.

    The add-on adds the default tolerance policy for the node.kubernetes.io/not-ready and node.kubernetes.io/unreachable taints, respectively. The tolerance time window is 60s.

    For details, see Taints and Tolerations.

  5. Click Install.

Components

Table 3 nginx-ingress component

Component

Description

Resource Type

cceaddon-nginx-ingress-controller

Nginx Ingress controller, which provides flexible routing and forwarding for clusters

Deployment

cceaddon-nginx-ingress-default-backend

Default backend of Nginx Ingress. The message "default backend - 404" is returned.

Deployment

Anti-affinity Deployment for Workloads and nginx-ingress-controller

The node where nginx-ingress-controller is running and the containers running on the node cannot access Nginx Ingress. To prevent this problem, configure an anti-affinity rule to tell the scheduler not to co-locate the workload and nginx-ingress-controller on the same node.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:aplpine
        imagePullPolicy: IfNotPresent
        name: nginx
      imagePullSecrets:
      - name: default-secret
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:    # Use the labels of nginx-ingress-controller to implement anti-affinity.
                  - key: app
                    operator: In
                    values:
                      - nginx-ingress
                  - key: component
                    operator: In
                    values:
                      - controller
              namespaces:
                - kube-system
              topologyKey: kubernetes.io/hostname

Change History

Table 4 Release history

Add-on Version

Supported Cluster Version

New Feature

Community Version

2.4.6

v1.25

v1.27

v1.28

  • CCE clusters 1.28 are supported.
  • Supported admission verification.
  • Supported graceful shutdown and hitless upgrade.
  • Supported equivalent distribution of add-on instances in multi-AZ deployment mode.
  • Fixed the CVE-2023-44487 vulnerability.

1.9.3

2.3.5

v1.27

None

1.8.0

2.2.42

v1.23

v1.25

  • Supported graceful shutdown and hitless upgrade.
  • Supported equivalent distribution of add-on instances in multi-AZ deployment mode.

1.5.1

2.2.7

v1.25

  • Synchronizes time zones used by add-ons and nodes.
  • Supports IPv4 and IPv6 dual stack.

1.5.1

2.2.3

v1.25

  • Supports anti-affinity scheduling of pods on nodes in different AZs.
  • Adds the tolerance time during which the pods with temporary storage volumes cannot be scheduled.
  • The default taint tolerance duration is changed to 60s.

1.5.1

2.2.1

v1.25

  • CCE clusters 1.25 are supported.
  • Updates the add-on to its community version v1.5.1.

1.5.1

2.1.33

v1.19

v1.21

v1.23

  • Supported graceful shutdown and hitless upgrade.
  • Supported equivalent distribution of add-on instances in multi-AZ deployment mode.

1.2.1

2.1.9

v1.19

v1.21

v1.23

  • Supports anti-affinity scheduling of pods on nodes in different AZs.
  • The default taint tolerance duration is changed to 60s.
  • Synchronizes time zones used by add-ons and nodes.
  • Supports IPv4 and IPv6 dual stack.

1.2.1

2.1.5

v1.19

v1.21

v1.23

  • Supports anti-affinity scheduling of pods on nodes in different AZs.
  • The default taint tolerance duration is changed to 60s.

1.2.1

2.1.3

v1.19

v1.21

v1.23

Enables publishService for nginx-ingress.

1.2.1

2.1.1

v1.19

v1.21

v1.23

Updates the add-on to its community version v1.2.1.

1.2.1

2.1.0

v1.19

v1.21

v1.23

  • Updates the add-on to its community version v1.2.0.
  • Fixed the CVE-2021-25746 vulnerability and added rules to disable some annotations values that may cause unauthorized operations.
  • Fixed the CVE-2021-25745 vulnerability and added rules to disable some access paths that may cause unauthorized operations.

1.2.0

2.0.1

v1.19

v1.21

v1.23

  • CCE clusters 1.23 are supported.
  • Updates the add-on to its community version v1.1.1.

1.1.1

1.3.2

v1.15

v1.17

v1.19

v1.21

  • CCE clusters 1.21 are supported.
  • Updates the add-on to its community version v0.49.3.

0.49.3

1.2.6

v1.15

v1.17

v1.19

Adds the default seccomp profile.

0.46.0

1.2.5

v1.15

v1.17

v1.19

Updates the add-on to its community version v0.46.0.

0.46.0

1.2.3

v1.15

v1.17

v1.19

CCE clusters 1.19 are supported.

0.43.0

1.2.2

v1.15

v1.17

Updates the add-on to its community version v0.43.0.

0.43.0