title: Configuring Ingress with Kubernetes Ingress resource keywords:
This tutorial will walk you through on how you can configure APISIX Ingress with the default Kubernetes Ingress resource.
Also see:
Before you move on, make sure you:
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
We can use the default Kubernetes Ingress resource to configure APISIX Ingress. The example below shows a sample configuration that creates a Route to the httpbin service:
# use v1beta1 if your Kubernetes cluster version is older than v1.19.0 apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: httpserver-ingress spec: # we use APISIX Ingress and it watches Ingress resources with "apisix" ingressClassName ingressClassName: apisix rules: - host: local.httpbin.org http: paths: - backend: service: name: httpbin port: number: 80 path: / pathType: Prefix
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
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:
{ "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" }