This example demonstrates how to use an HTTPRoute to expose simple "hello world" applications through the HAProxy Kubernetes Gateway, using both prefix and exact path matching.
This example deploys the following resources:
- A GatewayClass named
haproxythat defines a class of Gateways that can be provisioned by the HAProxy Kubernetes Gateway. - A Gateway named
hug-gatewaythat requests a listener on port31080for HTTP traffic. - An HTTPRoute that directs traffic for
blue-green.haproxy.localto two different services with weights:- 90% of the traffic is sent to the
blueservice. - 10% of the traffic is sent to the
greenservice.
- 90% of the traffic is sent to the
- Two Deployments and Services for the echo applications:
blue: A simple echo server representing the "blue" version.green: Another simple echo server representing the "green" version.
kubectl apply -f .$ cat /usr/local/hug/maps/hug_default_hug-gateway_http/path_prefix.map
blue-green.haproxy.local/ {"a":"wr","l":"hug_default_blue_8888__:90,hug_default_green_8888__:10"}Use curl to send a request to the services through the Gateway.
GW_IP=$(kubectl get gateway hug-gateway -n default -o jsonpath='{.status.addresses[0].value}')
curl http://$GW_IP:31080/hostname -H "Host: blue-green.haproxy.local"You should see a response from the services, confirming that the traffic was routed correctly (one of two services).
blue-77f7ddfc87-cmr94
green-665cfb454f-qs68k$ sh test.sh
90 blue
10 greenNote that due to randomness, 9/1 ratio might slightly differ