Create a Service and Route
Use KongService
and KongRoute
resources to define and expose your service through the Konnect Gateway.
Prerequisites
Series Prerequisites
This page is part of the Get Started with the Kong Gateway Operator series.
Complete the previous page, Create a Control Plane before completing this page.
How Kubernetes resources map to Kong Gateway entities
A Kubernetes Service represents an application running on a group of Pods. In Kong Gateway, this maps to a Service
and Upstream
.
- The KongService defines protocol-specific information and connection settings to reach the upstream application.
- The Upstream defines load balancing and health checking behavior across backend targets.
flowchart LR H(Request traffic) subgraph Pods direction LR E(Target) F(Target) G(Target) end subgraph Kubernetes Service direction TB C(Service) D(Upstream) end subgraph Ingress / HTTPRoute direction LR A(Route) B(Route) end A --> C B --> C C --> D D --> E D --> F D --> G H --> A linkStyle 6 stroke:#b6d7a8
Create a KongService
The KongService
resource is used to define an upstream service that Konnect will route traffic to. This must include a reference to a KonnectGatewayControlPlane
to associate the service with your Konnect environment.
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 -
Create a KongRoute
Define a KongRoute
to expose the Service you created. The Route determines how requests are matched and routed to the associated Service.
echo '
kind: KongRoute
apiVersion: configuration.konghq.com/v1alpha1
metadata:
name: route
namespace: kong
spec:
name: route
protocols:
- http
paths:
- "/"
serviceRef:
type: namespacedRef
namespacedRef:
name: service
' | kubectl apply -f -
Validation
You can validate from the command line or Gateway Manager UI to confirm that both the KongService
and KongRoute
have been provisioned and are in a valid state:
Check that Programmed
is True
on the service
resource:
You can verify the KongService
was reconciled successfully by checking its Programmed
condition.
kubectl get -n kong kongservice service \
-o=jsonpath='{.status.conditions[?(@.type=="Programmed")]}' | jq
The output should look similar to this:
{
"observedGeneration": 1,
"reason": "Programmed",
"status": "True",
"type": "Programmed"
}
Check that Programmed
is True
on the route
resource:
You can verify the KongRoute
was reconciled successfully by checking its Programmed
condition.
kubectl get -n kong kongroute route \
-o=jsonpath='{.status.conditions[?(@.type=="Programmed")]}' | jq
The output should look similar to this:
{
"observedGeneration": 1,
"reason": "Programmed",
"status": "True",
"type": "Programmed"
}