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

     1  # Cross-Namespace Configuration
     2  
     3  In this example we use the [VirtualServer and VirtualServerRoute](https://docs.nginx.com/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/) resources to configure load balancing for the modified cafe application from the [Basic Configuration](../basic-configuration/) example. We have put the load balancing configuration as well as the deployments and services into multiple namespaces. Instead of one namespace, we now use three: `tea`, `coffee`, and `cafe`.
     4  * In the tea namespace, we create the tea deployment, service, and the corresponding load-balancing configuration.
     5  * In the coffee namespace, we create the coffee deployment, service, and the corresponding load-balancing configuration.
     6  * In the cafe namespace, we create the cafe secret with the TLS certificate and key and the load-balancing configuration for the cafe application. That configuration references the coffee and tea configurations.
     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 HTTPS port of the Ingress Controller into a shell variable:
    16      ```
    17      $ IC_HTTPS_PORT=<port number>
    18      ```
    19  
    20  ## Step 1 - Create Namespaces
    21  
    22  Create the required tea, coffee, and cafe namespaces:
    23  ```
    24  $ kubectl create -f namespaces.yaml 
    25  ```
    26  
    27  ## Step 2 - Deploy the Cafe Application
    28  
    29  1. Create the tea deployment and service in the tea namespace:
    30      ```
    31      $ kubectl create -f tea.yaml 
    32      ```
    33  1. Create the coffee deployment and service in the coffee namespace:
    34      ```
    35      $ kubectl create -f coffee.yaml
    36      ```
    37  
    38  ## Step 3 - Configure Load Balancing and TLS Termination
    39  
    40  1. Create the VirtualServerRoute resource for tea in the tea namespace:
    41      ```
    42      $ kubectl create -f tea-virtual-server-route.yaml
    43      ```
    44  1. Create the VirtualServerRoute resource for coffee in the coffee namespace:
    45      ```
    46      $ kubectl create -f coffee-virtual-server-route.yaml
    47      ```
    48  1. Create the secret with the TLS certificate and key in the cafe namespace:
    49      ```
    50      $ kubectl create -f cafe-secret.yaml
    51      ```
    52  1. Create the VirtualServer resource for the cafe app in the cafe namespace:
    53      ```
    54      $ kubectl create -f cafe-virtual-server.yaml
    55      ```
    56  
    57  ## Step 4 - Test the Configuration
    58  
    59  1. Check that the configuration has been successfully applied by inspecting the events of the VirtualServerRoutes and VirtualServer:
    60      ```
    61      $ kubectl describe virtualserverroute tea -n tea
    62      . . .
    63      Events:
    64        Type     Reason                 Age   From                      Message
    65        ----     ------                 ----  ----                      -------
    66        Warning  NoVirtualServersFound  2m    nginx-ingress-controller  No VirtualServer references VirtualServerRoute tea/tea
    67        Normal   AddedOrUpdated         1m    nginx-ingress-controller  Configuration for tea/tea was added or updated
    68      
    69      $ kubectl describe virtualserverroute coffee -n coffee 
    70      . . .
    71      Events:
    72        Type     Reason                 Age   From                      Message
    73        ----     ------                 ----  ----                      -------
    74        Warning  NoVirtualServersFound  2m    nginx-ingress-controller  No VirtualServer references VirtualServerRoute coffee/coffee
    75        Normal   AddedOrUpdated         1m    nginx-ingress-controller  Configuration for coffee/coffee was added or updated
    76  
    77      $ kubectl describe virtualserver cafe -n cafe
    78      . . .
    79      Events:
    80        Type    Reason          Age   From                      Message
    81        ----    ------          ----  ----                      -------
    82        Normal  AddedOrUpdated  1m    nginx-ingress-controller  Configuration for cafe/cafe was added or updated
    83      ```
    84  1. Access the application using curl. We'll use curl's `--insecure` option to turn off certificate verification of our self-signed certificate and `--resolve` option to set the IP address and HTTPS port of the Ingress Controller to the domain name of the cafe application:
    85      
    86      To get coffee:
    87      ```
    88      $ curl --resolve cafe.example.com:$IC_HTTPS_PORT:$IC_IP https://cafe.example.com:$IC_HTTPS_PORT/coffee --insecure
    89      Server address: 10.16.1.193:80
    90      Server name: coffee-7dbb5795f6-mltpf
    91      ...
    92      ```
    93      If your prefer tea:
    94      ```
    95      $ curl --resolve cafe.example.com:$IC_HTTPS_PORT:$IC_IP https://cafe.example.com:$IC_HTTPS_PORT/tea --insecure
    96      Server address: 10.16.0.157:80
    97      Server name: tea-7d57856c44-674b8
    98      ...