|
| 1 | +# HTTPS Termination Example |
| 2 | + |
| 3 | +In this example we expand on the simple [cafe-example](../cafe-example) by adding HTTPS termination to our routes. |
| 4 | + |
| 5 | +## Running the Example |
| 6 | + |
| 7 | +## 1. Deploy NGINX Kubernetes Gateway |
| 8 | + |
| 9 | +1. Follow the [installation instructions](https://github.com/nginxinc/nginx-kubernetes-gateway/blob/main/README.md#run-nginx-gateway) to deploy NGINX Gateway. |
| 10 | + |
| 11 | +1. Save the public IP address of NGINX Kubernetes Gateway into a shell variable: |
| 12 | + |
| 13 | + ``` |
| 14 | + GW_IP=XXX.YYY.ZZZ.III |
| 15 | + ``` |
| 16 | + |
| 17 | +1. Save the HTTPS port of NGINX Kubernetes Gateway: |
| 18 | + |
| 19 | + ``` |
| 20 | + GW_HTTPS_PORT=port |
| 21 | + ``` |
| 22 | + |
| 23 | +## 2. Deploy the Cafe Application |
| 24 | + |
| 25 | +1. Create the coffee and the tea deployments and services: |
| 26 | + |
| 27 | + ``` |
| 28 | + kubectl apply -f cafe.yaml |
| 29 | + ``` |
| 30 | + |
| 31 | +1. Check that the Pods are running in the `default` namespace: |
| 32 | + |
| 33 | + ``` |
| 34 | + kubectl -n default get pods |
| 35 | + NAME READY STATUS RESTARTS AGE |
| 36 | + coffee-6f4b79b975-2sb28 1/1 Running 0 12s |
| 37 | + tea-6fb46d899f-fm7zr 1/1 Running 0 12s |
| 38 | + ``` |
| 39 | + |
| 40 | +## 3. Configure HTTPS Termination and Routing |
| 41 | + |
| 42 | +1. Create a secret with a TLS certificate and key: |
| 43 | + ``` |
| 44 | + kubectl apply -f cafe-secret.yaml |
| 45 | + ``` |
| 46 | + |
| 47 | + The TLS certificate and key in this secret are used to terminate the TLS connections for the cafe application. |
| 48 | + **Important**: This certificate and key are for demo purposes only. |
| 49 | + |
| 50 | +1. Create the `Gateway` resource: |
| 51 | + ``` |
| 52 | + kubectl apply -f gateway.yaml |
| 53 | + ``` |
| 54 | + |
| 55 | + This [gateway](./gateway.yaml) configures an `https` listener is to terminate TLS connections using the `cafe-secret` we created in the step 1. |
| 56 | + |
| 57 | +1. Create the `HTTPRoute` resources: |
| 58 | + ``` |
| 59 | + kubectl apply -f cafe-routes.yaml |
| 60 | + ``` |
| 61 | + |
| 62 | + To configure HTTPS termination for our cafe application, we will bind the `https` listener to our `HTTPRoutes` in [cafe-routes.yaml](./cafe-routes.yaml) using the [`parentRef`](https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io%2fv1alpha2.ParentReference) field: |
| 63 | + |
| 64 | + ```yaml |
| 65 | + parentRefs: |
| 66 | + - name: gateway |
| 67 | + namespace: default |
| 68 | + sectionName: https |
| 69 | + ``` |
| 70 | +
|
| 71 | +## 4. Test the Application |
| 72 | +
|
| 73 | +To access the application, we will use `curl` to send requests to the `coffee` and `tea` services. |
| 74 | +Since our certificate is self-signed, we'll use curl's `--insecure` option to turn off certificate verification. |
| 75 | + |
| 76 | +To get coffee: |
| 77 | + |
| 78 | +``` |
| 79 | +curl --resolve cafe.example.com:$GW_HTTPS_PORT:$GW_IP https://cafe.example.com:$GW_HTTPS_PORT/coffee --insecure |
| 80 | +Server address: 10.12.0.18:80 |
| 81 | +Server name: coffee-7586895968-r26zn |
| 82 | +``` |
| 83 | + |
| 84 | +To get tea: |
| 85 | + |
| 86 | +``` |
| 87 | +curl --resolve cafe.example.com:$GW_HTTPS_PORT:$GW_IP https://cafe.example.com:$GW_HTTPS_PORT/tea --insecure |
| 88 | +Server address: 10.12.0.19:80 |
| 89 | +Server name: tea-7cd44fcb4d-xfw2x |
| 90 | +``` |
0 commit comments