github.com/nginxinc/kubernetes-ingress@v1.12.5/examples-of-custom-resources/advanced-routing/README.md (about)

     1  # Advanced Routing
     2  
     3  In this example we use the [VirtualServer](https://docs.nginx.com/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/) resource to configure advanced routing for the cafe application from the [Basic Configuration](../basic-configuration/) example, for which we have introduced the following changes:
     4  * Instead of one version of the tea service, we have two: `tea-post-svc` and `tea-svc`. We send POST requests for tea to `tea-post-svc` and non-POST requests, such as GET requests, to `tea-svc`.
     5  * Instead of one version of the coffee service, we have two: `coffee-v1-svc` and `coffee-v2-svc`. We send requests that include the cookie `version` set to `v2` to `coffee-v2-svc` and all other requests to `coffee-v1-svc`.
     6  * To simplify the example, we have removed TLS termination.
     7  
     8  ## Prerequisites  
     9  
    10  1. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/) instructions to deploy the Ingress Controller with custom resources enabled.
    11  1. Save the public IP address of the Ingress Controller into a shell variable:
    12      ```
    13      $ IC_IP=XXX.YYY.ZZZ.III
    14      ```
    15  1. Save the HTTP port of the Ingress Controller into a shell variable:
    16      ```
    17      $ IC_HTTP_PORT=<port number>
    18      ```
    19  
    20  ## Step 1 - Deploy the Cafe Application
    21  
    22  Create the coffee and the tea deployments and services:
    23  ```
    24  $ kubectl create -f cafe.yaml
    25  ```
    26  
    27  ## Step 2 - Configure Load Balancing
    28  
    29  Create the VirtualServer resource:
    30  ```
    31  $ kubectl create -f cafe-virtual-server.yaml
    32  ```
    33  
    34  ## Step 3 - Test the Configuration
    35  
    36  1. Check that the configuration has been successfully applied by inspecting the events of the VirtualServer:
    37      ```
    38      $ kubectl describe virtualserver cafe
    39      . . .
    40      Events:
    41        Type    Reason          Age   From                      Message
    42        ----    ------          ----  ----                      -------
    43        Normal  AddedOrUpdated  2s    nginx-ingress-controller  Configuration for default/cafe was added or updated
    44      ```
    45  1. Access the tea service using curl. We'll use curl's `--resolve` option to set the IP address and HTTP port of the Ingress Controller to the domain name of the cafe application:
    46      
    47      Send a POST request and confirm that the response comes from `tea-post-svc`:
    48      ```
    49      $ curl --resolve cafe.example.com:$IC_HTTP_PORT:$IC_IP http://cafe.example.com:$IC_HTTP_PORT/tea -X POST
    50      Server address: 10.16.1.188:80
    51      Server name: tea-post-b5dd479b4-6ssmh
    52      . . .
    53      ```
    54  
    55      Send a GET request and confirm that the response comes from `tea-svc`:
    56      ```
    57      $ curl --resolve cafe.example.com:$IC_HTTP_PORT:$IC_IP http://cafe.example.com:$IC_HTTP_PORT/tea
    58      Server address: 10.16.1.189:80
    59      Server name: tea-7d57856c44-2hsvr
    60      . . .
    61      ```
    62  
    63  1.  Access the coffee service:
    64      
    65      Send a request with the cookie `version=v2` and confirm that the response comes from `coffee-v2-svc`:
    66      ```
    67      $ curl --resolve cafe.example.com:$IC_HTTP_PORT:$IC_IP http://cafe.example.com:$IC_HTTP_PORT/coffee --cookie "version=v2"
    68      Server address: 10.16.1.187:80
    69      Server name: coffee-v2-7fd446968b-vkthp
    70      . . .
    71      ```
    72  
    73      Send a request without the cookie and confirm that the response comes from `coffee-v1-svc`:
    74      ```
    75      $ curl --resolve cafe.example.com:$IC_HTTP_PORT:$IC_IP http://cafe.example.com:$IC_HTTP_PORT/coffee
    76      Server address: 10.16.0.153:80
    77      Server name: coffee-v1-78754bdcfb-bs9nh
    78      . . .
    79      ```