You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Nginx Ingress
Creating Nginx Ingresses through kubectl
Copy page
Download PDF
Creating Nginx Ingresses through kubectl
Volcengine Kubernetes Engine (VKE) provides an Nginx Ingress controller built on the community edition. It can convert Ingress rules to Nginx configurations and perform 7-layer traffic forwarding through Nginx. This topic introduces how to configure Nginx Ingress using YAML.​
warning​
NGINX Ingress support will soon be discontinued. For details, see [Product announcement] NGINX Ingress EOM.​
Prerequisites​
Creating Nginx Ingresses​
Forwarding based on domain names​
An NGINX Ingress can forward requests targeting different domain names to different back-end services.​
  1. Create a YAML file for an Ingress. The following is an example named nginx-ingress.yaml.​
  • ​
    apiVersion: networking.k8s.io/v1​
    kind: Ingress​
    metadata:​
    name: nginx-ingress # The name of the Ingress.​
    namespace: default # Namespace of the Ingress​
    spec:​
    ingressClassName: nginx # Specify the Ingress Controller.​
    rules:​
    - host: first.example.com # The domain name for external access.​
    http:​
    paths:​
    - pathType: Prefix # Path matching rule, with Prefix (prefix matching) as the default setting.​
    path: / # The matching path for the request.​
    backend:​
    service:​
    name: service-demo-a # The name of the service to forward requests to.​
    port: ​
    number: 80 # The service port number to forward to.​
    - host: second.example.com # Domain names for external access​
    http:​
    paths:​
    - pathType: Prefix # The path matching rule. Valid values: Exact and Prefix.​
    path: / # The matching path for the request.​
    backend:​
    service:​
    name: service-demo-b # The name of the service to forward requests to.​
    port: ​
    number: 80 # The service port number to forward to.​
    ​
  1. Execute the following command to create an Ingress.​
  • ​
    kubectl apply -f nginx-ingress.yaml​
    ​
Forwarding based on paths​
An NGINX Ingress supports forwarding requests targeting different paths on the same domain name to different back-end services.​
  1. Create a YAML file for Ingress. The following is an example named nginx-ingress.yaml.​
  • ​
    apiVersion: networking.k8s.io/v1​
    kind: Ingress​
    metadata:​
    name: nginx-ingress # The name of the Ingress.​
    namespace: default # Namespace of the Ingress​
    spec:​
    ingressClassName: nginx # Specify the Ingress Controller.​
    rules:​
    - host: example.com # The domain name for external access.​
    http:​
    paths:​
    - path: /foo # The path that matches the request.​
    pathType: Prefix # The path matching rule. Default value: Prefix.​
    backend:​
    service:​
    name: service-demo-a # The name of the service to forward requests to.​
    port: ​
    number: 80 # The service port number to forward to.​
    - path: /bar # The path that matches the request.​
    pathType: Prefix # The path matching rule. Default value: Prefix.​
    backend:​
    service:​
    name: service-demo-b # The name of the service to forward requests to.​
    port: ​
    number: 80 # The service port number to forward to.​
    ​
  1. Execute the following command to create an Ingress.​
  • ​
    kubectl apply -f nginx-ingress.yaml​
    ​
Using custom Nginx Ingress controllers​
VKE supports deploying multiple independent Nginx Ingress Controller services in a cluster at the same time. For details, see Deploying multiple NGINX Ingress controllers.​
You can use these NGINX Ingress controllers to provide different services externally as required. Procedure:​
  1. Create a YAML file for Ingress. The following is an example named nginx-ingress.yaml. Specifically, use the name in the spec.ingressClassName field to specify the Nginx Ingress controller service. In the following example, the controller user-ingress-nginx is specified.​
  • ​
    apiVersion: networking.k8s.io/v1​
    kind: Ingress​
    metadata:​
    name: ingress-demo # The name of the Ingress.​
    namespace: default # The namespace where the Ingress is located.​
    spec:​
    ingressClassName: user-ingress-nginx # The name of the custom NGINX Ingress controller.​
    rules:​
    - host: example.com # The domain name for external access.​
    http:​
    paths:​
    - pathType: Prefix​
    path: /​
    backend:​
    service:​
    name: service-demo # The name of the service that the Ingress connects to.​
    port:​
    number: 80 # The port number for the Ingress to connect to the service.​
    ​
  1. Execute the following command to create an application and a service.​
  • ​
    kubectl apply -f nginx-ingress.yaml​
    ​
Validating results​
Viewing configuration​
  1. Run the following command to view the Ingress configuration.​
  • ​
    kubectl get ingress​
    ​
  • If the response is similar to the following one, the Ingress has been created. The address 180.xxx.xxx.xxx is the public or private IP of the CLB configured for the Nginx Ingress.​
  • ​
    NAME CLASS HOSTS ADDRESS PORTS AGE​
    nginx-ingress nginx example.com 180.xxx.xxx.xxx 80 74s​
    ​
Testing the connections to services​
Run the following command to access the service by using the domain name.​
​
curl -H "Host: example.com" http://180.xxx.xxx.xxx​
​
If the response is similar to the following one, the back-end service is accessible through the domain name.​
​
<!DOCTYPE html>​
<html>​
<head>​
<title>Welcome to nginx!</title>​
<style>​
html { color-scheme: light dark; }​
body { width: 35em; margin: 0 auto;​
font-family: Tahoma, Verdana, Arial, sans-serif; }​
</style>​
</head>​
<body>​
<h1>Welcome to nginx!</h1>​
<p>If you see this page, the nginx web server is successfully installed and​
working. Further configuration is required.</p>​
​
<p>For online documentation and support please refer to​
<a href="http://nginx.org/">nginx.org</a>.<br/>​
Commercial support is available at​
<a href="http://nginx.com/">nginx.com</a>.</p>​
​
<p><em>Thank you for using nginx.</em></p>​
</body>​
</html>​
​
​
Last updated: 2026.07.24 14:51:36