The purpose of this example is to provide instructions for running the K8s Gatewey API using Kong.
-
Helm v3.17.2 or newer
-
Kubernetes v1.32.3 or newer
-
Minikube v1.35.0 or newer
-
OrbStack 1.10.3 or newer
Note: This tutorial was updated on macOS 15.3.2 (Sequoia). The below steps don't work with Docker Desktop v4.34.3 because it doesn't expose Linux VM IP addresses to the host OS (i.e. macOS).
-
clone GitHub repository
git clone https://github.com/conradwt/k8s-gateway-api-using-kong.git
-
change directory
cd k8s-gateway-api-using-kong
-
create Minikube cluster
minikube start -p gateway-api-kong --nodes=3 --kubernetes-version=v1.32.3
-
install MetalLB
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.9/config/manifests/metallb-native.yaml
-
locate the K8s cluster's subnet
docker network inspect gateway-api-kong | jq '.[0].IPAM.Config[0]["Subnet"]'
The results should look something like the following:
"194.1.2.0/24",
Then one can use an IP address range like the following:
194.1.2.100-194.1.2.110
-
create the
01-metallb-address-pool.yaml
filecp 01-metallb-address-pool.yaml.example 01-metallb-address-pool.yaml
-
update the
01-metallb-address-pool.yaml
apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: demo-pool namespace: metallb-system spec: addresses: - 194.1.2.100-194.1.2.110
Note: The IP range needs to be in the same range as the K8s cluster,
gateway-api-kong
. -
apply the address pool manifest
kubectl apply -f 01-metallb-address-pool.yaml
-
apply Layer 2 advertisement manifest
kubectl apply -f 02-metallb-advertise.yaml
-
apply deployment manifest
kubectl apply -f 03-nginx-deployment.yaml
-
apply service manifest
kubectl apply -f 04-nginx-service-loadbalancer.yaml
-
check that your service has an IP address
kubectl get svc nginx-service
The results should look something like the following:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-service LoadBalancer 10.106.207.172 194.1.2.100 80:32000/TCP 17h
-
test connectivity to
nginx-service
endpoint via external IP addresscurl 194.1.2.100
The results should look something like the following:
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
-
install the Gateway API CRDs
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.1.0/standard-install.yaml
-
create the Gateway and GatewayClass resources
kubectl apply -f 05-gateway.yaml
-
install Kong
helm repo add kong https://charts.konghq.com helm repo update
-
install Kong Ingress Controller and Kong Gateway
helm install kong kong/ingress -n kong --create-namespace
-
populate $GATEWAY_IP for future commands:
export GATEWAY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}') echo $GATEWAY_IP
-
verify the gateway IP
curl -i $GATEWAY_IP
The results should look something like the following:
HTTP/1.1 404 Not Found Content-Type: application/json; charset=utf-8 Connection: keep-alive Content-Length: 48 X-Kong-Response-Latency: 0 Server: kong/3.0.0 {"message":"no Route matched with those values"}
-
deploy the X service
kubectl apply -f 06-sample-service.yaml
-
create HTTPRoute for our deployed service
kubectl apply -f 07-sample-httproute.yaml
-
test the routing rule
curl -i $GATEWAY_IP/echo
The results should look like this:
HTTP/1.1 200 OK Content-Type: text/plain; charset=utf-8 Content-Length: 140 Connection: keep-alive Date: Fri, 21 Apr 2023 12:24:55 GMT X-Kong-Upstream-Latency: 0 X-Kong-Proxy-Latency: 1 Via: kong/3.2.2 Welcome, you are connected to node docker-desktop. Running on Pod echo-7f87468b8c-tzzv6. In namespace default. With IP address 10.1.0.237. ...
-
teardown the cluster
minikube delete --profile gateway-api-kong