Proxy HTTPS Traffic with TLS Termination

Related Documentation
TL;DR

Create an HTTPRoute or Ingress resource, which will then be converted into a Kong Gateway Service and Route. Specify a Kubernetes Secret containing a TLS certificate to terminate HTTPS requests using Kong Gateway.

Prerequisites

If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.

  1. The following Konnect items are required to complete this tutorial:
    • Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
  2. Set the personal access token as an environment variable:

    export KONNECT_TOKEN='YOUR KONNECT TOKEN'
    
    Copied to clipboard!

Generate a TLS certificate

  1. Create a test certificate for the demo.example.com hostname. This will be used to secure TLS traffic.

    Older OpenSSL versions, including the version provided with macOS Monterey, require using the alternative version of this command.

  2. Create a Secret containing the certificate:

     kubectl create secret -n kong tls demo.example.com --cert=./server.crt --key=./server.key
    
    Copied to clipboard!

Route HTTPs traffic

To listen for HTTPS traffic, configure an additional TLS listener on your Gateway resource:

kubectl patch -n kong --type=json gateway kong -p='[
    {
        "op":"add",
        "path":"/spec/listeners/-",
        "value":{
            "name": "https",
            "port": 443,
            "protocol":"HTTPS",
            "hostname":"demo.example.com",
            "allowedRoutes": {
              "namespaces": {
                "from": "All"
              }
            },
            "tls": {
              "mode": "Terminate",
              "certificateRefs":[{
                "group":"",
                "kind":"Secret",
                "name":"demo.example.com"
              }]
            }
        }
    }
]'
Copied to clipboard!

Create an HTTPRoute

To route HTTP traffic, you need to create an HTTPRoute or an Ingress resource pointing at your Kubernetes Service.

Validate your configuration

Once the resource has been reconciled, you’ll be able to call the /echo endpoint and Kong Gateway will route the request to the echo service.

curl -k "https://$PROXY_IP/echo" \
     -H "Host: demo.example.com"
Copied to clipboard!

Cleanup

kubectl delete -n kong -f https://developer.konghq.com/manifests/kic/echo-service.yaml
Copied to clipboard!

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!