Create a Route with Kong Gateway Operator
Create a KongService
object , then create a KongRoute
and associate it to the KongService
.
Prerequisites
Series Prerequisites
This page is part of the Deploy Hybrid DataPlanes with Kong Gateway Operator series.
Complete the previous page, Deploy a DataPlane before completing this page.
Create a Service
Creating the KongService
object in your Kubernetes cluster will provision a Kong Konnect service in your Gateway Manager. You can refer to the CR API to see all the available fields.
Your KongService
must be associated with a KonnectGatewayControlPlane
object that you’ve created in your cluster.
Create a KongService
by applying the following YAML manifest:
echo '
kind: KongService
apiVersion: configuration.konghq.com/v1alpha1
metadata:
name: service
namespace: kong
spec:
name: service
host: httpbin.konghq.com
controlPlaneRef:
type: konnectNamespacedRef
konnectNamespacedRef:
name: gateway-control-plane
' | kubectl apply -f -
At this point, you should see the Service in the Gateway Manager UI.
Create a Route
Creating the KongRoute
object in your Kubernetes cluster will provision a Kong Konnect Route in
your Gateway Manager.
You can refer to the CR API to see all the available fields.
Associate a Route with a Service
You can create a KongRoute
associated with a KongService
by applying the following YAML manifest:
echo '
kind: KongRoute
apiVersion: configuration.konghq.com/v1alpha1
metadata:
name: route-with-service
namespace: kong
spec:
name: route-with-service
protocols:
- http
paths:
- "/"
serviceRef:
type: namespacedRef
namespacedRef:
name: service
' | kubectl apply -f -
Send test traffic
After the Service and Route are created, send traffic to the proxy. Kong Gateway will forward the request to httpbin.konghq.com
. You can use the /anything
endpoint to echo the request made in the response.
To make a request to the proxy, fetch the LoadBalancer IP address using kubectl get services
:
NAME=$(kubectl get -o yaml -n kong service | yq '.items[].metadata.name | select(contains("dataplane-ingress"))')
export PROXY_IP=$(kubectl get svc -n kong $NAME -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}')
echo "Proxy IP: $PROXY_IP"
Note: If your cluster can’t provision LoadBalancer type Services, then you might not receive an IP address.
Test the routing rules by sending a request to the proxy IP address:
curl "$PROXY_IP/anything/hello"