|
| 1 | +# TransportServer SNI |
| 2 | + |
| 3 | +In this example we create two different TransportServers that listen on the same interface, which are distinguished by their Host field. |
| 4 | +The applications (a TCP echo server, and MongoDB) will be accessed via `ncat` and `mongosh`. |
| 5 | +The `ncat` binary is available via `nmap`. On mac/linux this can be installed via homebrew/linuxbrew with `brew install nmap` |
| 6 | +`mongosh` installation instructions are [available here](https://www.mongodb.com/docs/mongodb-shell/install/). |
| 7 | + |
| 8 | +## Create a GlobalConfiguration resource with the following listener |
| 9 | + |
| 10 | +```yaml |
| 11 | +listeners: |
| 12 | + - name: tcp-listener |
| 13 | + port: 7000 |
| 14 | + protocol: TCP |
| 15 | +``` |
| 16 | +
|
| 17 | +## Add a custom port to the NGINX Ingress Controller pod with the Helm chart |
| 18 | +
|
| 19 | +```yaml |
| 20 | +controller.customPorts: |
| 21 | + - name: port |
| 22 | + containerPort: 7000 |
| 23 | + protocol: TCP |
| 24 | +``` |
| 25 | +
|
| 26 | +## Add a custom port to the NGINX Ingress Controller service |
| 27 | +
|
| 28 | +```yaml |
| 29 | +controller.service.customPorts: |
| 30 | + - name: tcp-port |
| 31 | + port: 7000 |
| 32 | + protocol: TCP |
| 33 | + targetPort: 7000 |
| 34 | +``` |
| 35 | +
|
| 36 | +## Use `kubectl` to create the cafe-secret, and mongo-secret. These secrets are used for TLS in the TransportServers |
| 37 | + |
| 38 | +`kubectl apply -f cafe-secret.yaml` |
| 39 | +`kubectl apply -f mongo-secret.yaml` |
| 40 | + |
| 41 | +## Create the mongo and tcp echo example applications |
| 42 | + |
| 43 | +`kubectl apply -f mongo.yaml` |
| 44 | +`kubectl apply -f tcp-echo-server.yaml` |
| 45 | + |
| 46 | +## Wait until these are ready |
| 47 | + |
| 48 | +`kubectl get deploy -w` |
| 49 | + |
| 50 | +## Create the TransportServers for each application |
| 51 | + |
| 52 | +`kubectl apply -f cafe-transport-server.yaml` |
| 53 | +`kubectl apply -f mongo-transport-server.yaml` |
| 54 | + |
| 55 | +## Ensure they are in valid state |
| 56 | + |
| 57 | +`kubectl get ts` |
| 58 | + |
| 59 | +```shell |
| 60 | +NAME STATE REASON AGE |
| 61 | +cafe-ts Valid AddedOrUpdated 2m |
| 62 | +mongo-ts Valid AddedOrUpdated 2m |
| 63 | +``` |
| 64 | + |
| 65 | +## Set up /etc/hosts or DNS |
| 66 | + |
| 67 | +This example uses a local NGINX Ingress Controller instance, so the /etc/hosts file |
| 68 | +is being used to set cafe.example.com and mongo.example.com to localhost. |
| 69 | +In a production instance, the server names would be set at the DNS layer. |
| 70 | +`cat /etc/hosts` |
| 71 | + |
| 72 | +```shell |
| 73 | +... |
| 74 | +127.0.0.1 cafe.example.com |
| 75 | +127.0.0.1 mongo.example.com |
| 76 | +``` |
| 77 | + |
| 78 | +## Expose port 7000 of the LoadBalancer service |
| 79 | + |
| 80 | +`kubectl port-forward svc/my-release-nginx-ingress-controller 7000:7000` |
| 81 | + |
| 82 | +## Use `ncat` to ping cafe.example.com on port 7000 with SSL |
| 83 | + |
| 84 | +`ncat --ssl cafe.example.com 7000` |
| 85 | +When you write a message you should receive the following response: |
| 86 | + |
| 87 | +```shell |
| 88 | +hi |
| 89 | +hi |
| 90 | +``` |
| 91 | + |
| 92 | +Close the connection (CTRL+ c), then view the NGINX Ingress Controller logs. |
| 93 | + |
| 94 | +The request and response should both be 2 bytes. |
| 95 | + |
| 96 | +```shell |
| 97 | +127.0.0.1 [24/Sep/2024:15:48:58 +0000] TCP 200 3 3 2.702 "- |
| 98 | +``` |
| 99 | + |
| 100 | +## Use mongosh to connect to the mongodb container through the TransportServer on port 7000 |
| 101 | + |
| 102 | +`mongosh --host mongo.example.com --port 7000 --tls --tlsAllowInvalidCertificates` |
| 103 | + |
| 104 | +```shell |
| 105 | +test> show dbs |
| 106 | +admin 40.00 KiB |
| 107 | +config 60.00 KiB |
| 108 | +local 40.00 KiB |
| 109 | +test> |
| 110 | +``` |
0 commit comments