|
| 1 | +# curl --header "Host: offload.haproxy.local" --resolve "offload.haproxy.local":31443:172.18.0.2 https://offload.haproxy.local:31443/hostname -k -v |
| 2 | + |
| 3 | +# Hello World HTTPRoute with HTTPS offload Example |
| 4 | + |
| 5 | +This example demonstrates how to use an HTTPRoute to expose simple "hello world" applications through the HAProxy Kubernetes Gateway, with HTTPS offload. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## What is being deployed |
| 10 | + |
| 11 | +This example deploys the following resources: |
| 12 | + |
| 13 | +* A **GatewayClass** named `haproxy` that defines a class of Gateways that can be provisioned by the HAProxy Kubernetes Gateway. |
| 14 | +* A **Gateway** named `hug-gateway` that requests a listener on port `31080` for HTTP traffic. |
| 15 | +* An **HTTPRoute** that directs traffic for `offload.haproxy.local` to the service `hello-world-offload` |
| 16 | +* One **Deployment** and **Service** for the echo applications: |
| 17 | + * `hello-world-offload`: A simple echo server |
| 18 | +* A **Secret** `offload` |
| 19 | + |
| 20 | +## How to deploy in a `test` namepace |
| 21 | + |
| 22 | +```bash |
| 23 | +kubectl create ns test |
| 24 | +kubectl apply -f -n test . |
| 25 | +``` |
| 26 | + |
| 27 | +## How to check if the result is correct |
| 28 | + |
| 29 | +### POD |
| 30 | + |
| 31 | +```sh |
| 32 | +$ cat /usr/local/hug/maps/link1_test_hug-gateway_https/path_prefix.map |
| 33 | +https.haproxy.local/ link1_test_hello-world-offload_443__ |
| 34 | +``` |
| 35 | + |
| 36 | +### curl |
| 37 | + |
| 38 | +### From the Hug pod |
| 39 | +Use `curl` to send a request to the services through the Gateway. |
| 40 | + |
| 41 | +```sh |
| 42 | +curl --header "Host: offload.haproxy.local" --resolve "offload.haproxy.local":31443:127.0.0.1 https://offload.haproxy.local:31443/hostname -k |
| 43 | +``` |
| 44 | + |
| 45 | +You should see a response from the services, confirming that the traffic was routed correctly. |
| 46 | + |
| 47 | +```sh |
| 48 | +hello-world-offload-c6b56955d-4hjld |
| 49 | +``` |
| 50 | + |
| 51 | +### From outside the cluster |
| 52 | + |
| 53 | +Assuming that a NodePort Service like |
| 54 | + |
| 55 | +```yaml |
| 56 | +apiVersion: v1 |
| 57 | +kind: Service |
| 58 | +metadata: |
| 59 | + name: haproxy-unified-gateway |
| 60 | + namespace: haproxy-unified-gateway |
| 61 | +spec: |
| 62 | + selector: |
| 63 | + run: haproxy-unified-gateway |
| 64 | + type: NodePort |
| 65 | + ports: |
| 66 | + - name: http |
| 67 | + port: 31080 |
| 68 | + targetPort: 31080 |
| 69 | + # nodePort is needed for NodePort service type |
| 70 | + nodePort: 31080 |
| 71 | + protocol: TCP |
| 72 | + - name: https |
| 73 | + port: 31443 |
| 74 | + targetPort: 31443 |
| 75 | + # nodePort is needed for NodePort service type |
| 76 | + nodePort: 31443 |
| 77 | + protocol: TCP |
| 78 | + - name: stat |
| 79 | + port: 31024 |
| 80 | + targetPort: 31024 |
| 81 | +``` |
| 82 | +
|
| 83 | +Use `curl` to send a request to the services through the Gateway. |
| 84 | + |
| 85 | +```sh |
| 86 | +curl --header "Host: offload.haproxy.local" --resolve "offload.haproxy.local":31443:<node IP> https://offload.haproxy.local:31443/hostname -k |
| 87 | +``` |
| 88 | + |
| 89 | +You should see a response from the services, confirming that the traffic was routed correctly. |
| 90 | + |
| 91 | +```sh |
| 92 | +hello-world-offload-c6b56955d-4hjld |
| 93 | +``` |
| 94 | + |
| 95 | +### haproxy.cfg |
| 96 | +You can also check the generated `haproxy.cfg`. |
| 97 | + |
| 98 | +``` |
| 99 | +cat /usr/local/hug/haproxy.cfg |
| 100 | +``` |
| 101 | +
|
| 102 | +```sh |
| 103 | +frontend link1_test_hug-gateway_https from haproxytech # {"hug":{"Gateway":{"test/hug-gateway":{"Generation":1,"LinkID":"link1"}}}} |
| 104 | + mode http |
| 105 | + bind 0.0.0.0:31443 name v4 ssl crt-list /usr/local/hug/certlists/test_hug-gateway_https.list |
| 106 | + bind [::]:31443 name v6 ssl crt-list /usr/local/hug/certlists/test_hug-gateway_https.list |
| 107 | + acl route_is_json var(txn.route),bytes(0,1) -m str { # {"hug":"for lua routing"} |
| 108 | + http-request set-var(txn.base) base |
| 109 | + http-request set-var(txn.path) path |
| 110 | + http-request set-var(txn.host) req.hdr(Host),host_only |
| 111 | + http-request set-var(txn.route) base,map(/usr/local/hug/maps/link1_test_hug-gateway_https/path_exact.map) # {"hug":"exact domain + exact path"} |
| 112 | + http-request set-var(txn.route,ifnotexists) path,map(/usr/local/hug/maps/link1_test_hug-gateway_https/path_exact.map) # {"hug":"any domain + exact path"} |
| 113 | + http-request set-var(txn.route,ifnotexists) base,map_beg(/usr/local/hug/maps/link1_test_hug-gateway_https/path_prefix.map) # {"hug":"exact domain + path prefix"} |
| 114 | + http-request set-var(txn.route,ifnotexists) path,map_beg(/usr/local/hug/maps/link1_test_hug-gateway_https/path_prefix.map) # {"hug":"exact domain + path prefix"} |
| 115 | + http-request set-var(txn.route,ifnotexists) base,map_end(/usr/local/hug/maps/link1_test_hug-gateway_https/domain_wildcard_path_exact.map) # {"hug":"domain wildcard + exact path"} |
| 116 | + http-request set-var(txn.route,ifnotexists) path,map_reg(/usr/local/hug/maps/link1_test_hug-gateway_https/path_regex.map) # {"hug":"any domain + path regex"} |
| 117 | + http-request set-var(txn.route,ifnotexists) base,map_reg(/usr/local/hug/maps/link1_test_hug-gateway_https/path_regex.map) # {"hug":"domain wildcard + path prefix or regex, exact domain + path regex"} |
| 118 | + http-request lua.route if route_is_json # {"hug":"lua routing"} |
| 119 | + use_backend %[var(txn.backend)] if route_is_json |
| 120 | + use_backend %[var(txn.route)] |
| 121 | + default_backend backend_not_found |
| 122 | +``` |
| 123 | +Note the `bind` doing HTTPS termination. |
| 124 | + |
| 125 | +```sh |
| 126 | +backend link1_test_hello-world-offload_80__ from haproxytech # {"hug":{"HTTPRoute":{"test/route-hello-world-offload":{"Generation":2,"LinkID":"link1"}}}} |
| 127 | + mode http |
| 128 | + balance roundrobin |
| 129 | + option forwardfor |
| 130 | + no option abortonclose |
| 131 | + timeout server 50000 |
| 132 | + default-server check |
| 133 | + server SRV_8f3e9904fc22b571a9e21e8b158c09f79153cb9b 10.244.0.7:8888 enabled |
| 134 | +``` |
0 commit comments