Skip to main content
Version: 1.7.0

Configuring Ingress with Kubernetes Gateway API

This tutorial will walk you through on how you can configure APISIX Ingress with the Kubernetes Gateway API.

Also see:

Prerequisites#

Before you move on, make sure you have access to a Kubernetes cluster. This tutorial uses minikube.

Install Gateway API CRDs#

Kubernetes does not have the Gateway API CRDs installed out of the box. You can install it manually by running:

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.5.0/standard-install.yaml

Install APISIX Ingress and Enable Gateway API#

You can install APISIX and APISIX Ingress controller with Helm. To enable APISIX Ingress controller to work with the Gateway API, you can set the flag --set ingress-controller.config.kubernetes.enableGatewayAPI=true as shown below:

helm repo add apisix https://charts.apiseven.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
kubectl create ns ingress-apisix
helm install apisix apisix/apisix --namespace ingress-apisix \
--set gateway.type=NodePort \
--set ingress-controller.enabled=true \
--set ingress-controller.config.apisix.serviceNamespace=ingress-apisix \
--set ingress-controller.config.kubernetes.enableGatewayAPI=true

Deploy httpbin#

We will deploy a sample service, kennethreitz/httpbin, for this tutorial.

You can deploy it to your Kubernetes cluster by running:

kubectl run httpbin --image kennethreitz/httpbin --port 80
kubectl expose pod httpbin --port 80

Configuring Ingress#

We will use the HTTPRoute API to define Ingress. The example below shows a sample configuration that creates a Route to the httpbin service:

httpbin-ingress.yaml
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: httpbin-route
spec:
hostnames:
- local.httpbin.org
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: httpbin
port: 80

This configuration will route all requests with host local.httpbin.org to the httpbin service.

You can apply it by running:

kubectl apply -f httpbin-ingress.yaml

Test the created Routes#

If you followed along and used minikube and NodePort service to expose APISIX, you can access it through the Node IP of the service apisix-gateway. If the Node IP is not reachable directly (if you are on Darwin, Windows, or WSL), you can create a tunnel to access the service on your machine:

minikube service apisix-gateway --url -n ingress-apisix

Now, you can send a GET request to the created Route and it will be Routed to the httpbin service:

curl --location --request GET "localhost:57687/get?foo1=bar1&foo2=bar2" -H "Host: local.httpbin.org"

You will receive a response similar to:

output
{
"args": {
"foo1": "bar1",
"foo2": "bar2"
},
"headers": {
"Accept": "*/*",
"Host": "local.httpbin.org",
"User-Agent": "curl/7.84.0",
"X-Forwarded-Host": "local.httpbin.org"
},
"origin": "172.17.0.1",
"url": "http://local.httpbin.org/get?foo1=bar1&foo2=bar2"
}