Skip to content

conradwt/k8s-gateway-api-using-kong

Repository files navigation

K8s Gateway API Using Kong

The purpose of this example is to provide instructions for running the K8s Gatewey API using Kong.

Software Requirements

  • 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).

Tutorial Installation

  1. clone GitHub repository

    git clone https://github.com/conradwt/k8s-gateway-api-using-kong.git
  2. change directory

    cd k8s-gateway-api-using-kong
  3. create Minikube cluster

    minikube start -p gateway-api-kong --nodes=3 --kubernetes-version=v1.32.3
  4. install MetalLB

    kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.9/config/manifests/metallb-native.yaml
  5. 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
    
  6. create the 01-metallb-address-pool.yaml file

    cp 01-metallb-address-pool.yaml.example 01-metallb-address-pool.yaml
  7. 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.

  8. apply the address pool manifest

    kubectl apply -f 01-metallb-address-pool.yaml
  9. apply Layer 2 advertisement manifest

    kubectl apply -f 02-metallb-advertise.yaml
  10. apply deployment manifest

    kubectl apply -f 03-nginx-deployment.yaml
  11. apply service manifest

    kubectl apply -f 04-nginx-service-loadbalancer.yaml
  12. 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
    
  13. test connectivity to nginx-service endpoint via external IP address

    curl 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>
    
  14. install the Gateway API CRDs

    kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.1.0/standard-install.yaml
  15. create the Gateway and GatewayClass resources

    kubectl apply -f 05-gateway.yaml
  16. install Kong

    helm repo add kong https://charts.konghq.com
    helm repo update
  17. install Kong Ingress Controller and Kong Gateway

    helm install kong kong/ingress -n kong --create-namespace
  18. 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
  19. 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"}
    
  20. deploy the X service

    TODO rewrite for our defined service.

    kubectl apply -f 06-sample-service.yaml
  21. create HTTPRoute for our deployed service

    TODO rewrite for our defined service.

    kubectl apply -f 07-sample-httproute.yaml
  22. test the routing rule

    TODO rewrite for our defined service.

    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.
    ...
    
  23. teardown the cluster

    minikube delete --profile gateway-api-kong

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published