This section uses an Nginx workload as an example to describe how to create an Nginx ingress using kubectl.
In CCE clusters of v1.23 or later, the ingress version is switched to networking.k8s.io/v1.
Compared with v1beta1, v1 has the following differences in parameters:

vi ingress-test.yaml
Starting from cluster v1.23, the ingress version is switched from networking.k8s.io/v1beta1 to networking.k8s.io/v1. For details about the differences between v1 and v1beta1, see Ingress Description of networking.k8s.io/v1.
The following uses HTTP as an example to describe how to configure the YAML file:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-test
spec:
rules:
- host: ''
http:
paths:
- path: /
backend:
service:
name: <your_service_name> # Replace it with the name of your target Service.
port:
number: <your_service_port> # Replace it with the port number of your target Service.
property:
ingress.beta.kubernetes.io/url-match-mode: STARTS_WITH
pathType: ImplementationSpecific
ingressClassName: nginx # Nginx Ingress is used. If multiple Nginx Ingress controllers are installed in the cluster, replace nginx with the custom name of the controller associated with the ingress.
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-test
namespace: default
annotations:
kubernetes.io/ingress.class: nginx # Nginx Ingress is used.
spec:
rules:
- host: ''
http:
paths:
- path: '/'
backend:
serviceName: <your_service_name> # Replace it with the name of your target Service.
servicePort: <your_service_port> # Replace it with the port number of your target Service.
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
kubernetes.io/ingress.class |
Yes (only for clusters of v1.21 or earlier) |
String |
nginx: indicates that Nginx Ingress is used. This option is available only after the NGINX Ingress Controller add-on is installed. This parameter is mandatory when an ingress is created by calling the API. |
ingressClassName |
Yes (only for clusters of v1.23 or later) |
String |
nginx: indicates that Nginx Ingress is used. This option is available only after the NGINX Ingress Controller add-on is installed. If multiple Nginx Ingress controllers are installed in the cluster, replace nginx with the custom name of the controller associated with the ingress. Multiple NGINX Ingress Controller add-ons can be installed in one cluster if the add-on version is 2.5.4 or later. In this case, the value of this parameter must be the controller name customized during controller installation, which indicates that the ingress is managed by the controller. This parameter is mandatory when an ingress is created by calling the API. |
host |
No |
String |
Domain name for accessing the Service. By default, this parameter is left blank, and the domain name needs to be fully matched. Ensure that the domain name has been registered and archived. Once a domain name rule is configured, you must use the domain name for access. |
path |
Yes |
String |
User-defined route path. All external access requests must match host and path. NOTE:
|
ingress.beta.kubernetes.io/url-match-mode |
No |
String |
Route matching policy. Default: STARTS_WITH (prefix match) Options:
|
pathType |
Yes |
String |
Path type. This field is supported only by clusters of v1.23 or later.
See examples of ingress path matching. |
kubectl create -f ingress-test.yaml
If information similar to the following is displayed, the ingress has been created.
ingress/ingress-test created
View the created ingress.
kubectl get ingress
If information similar to the following is displayed, the ingress has been created and the workload is accessible.
NAME HOSTS ADDRESS PORTS AGE ingress-test * 121.**.**.** 80 10s
121.**.**.** indicates the IP address of the unified load balancer.