Configure Routes
Apache APISIX provides flexible gateway management capabilities based on routes, in which routing paths and target upstreams are defined.
This tutorial guides you through creating a Route using the APISIX Ingress Controller and verifying its behavior. You’ll configure a Route to a sample Upstream pointing to an httpbin service, then send a request to observe how APISIX proxies the traffic.
#
Prerequisites- Complete Get APISIX and APISIX Ingress Controller.
#
Set Up a Sample UpstreamInstall the httpbin example application on the cluster to test the configuration:
kubectl apply -f https://raw.githubusercontent.com/apache/apisix-ingress-controller/refs/heads/v2.0.0/examples/httpbin/deployment.yaml
#
Configure a RouteIn this section, you will create a Route that forwards client requests to the httpbin example application, an HTTP request and response service.
You can use either Gateway API, Ingress, or APISIX CRD resources to configure the route.
important
If you are using Gateway API, you should first configure the GatewayClass and Gateway resources:
Show configuration
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: apisix
spec:
controllerName: apisix.apache.org/apisix-ingress-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: apisix
spec:
gatewayClassName: apisix
listeners:
- name: http
protocol: HTTP
port: 80
infrastructure:
parametersRef:
group: apisix.apache.org
kind: GatewayProxy
name: apisix-config
If you are using Ingress or APISIX custom resources, you can proceed without additional configuration.
Create a Kubernetes manifest file for a Route that proxy requests to httpbin:
- Gateway API
- Ingress
- APISIX CRD
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: getting-started-ip
spec:
parentRefs:
- name: apisix
rules:
- matches:
- path:
type: Exact
value: /ip
backendRefs:
- name: httpbin
port: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: getting-started-ip
spec:
ingressClassName: apisix
rules:
- http:
paths:
- backend:
service:
name: httpbin
port:
number: 80
path: /ip
pathType: Exact
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: getting-started-ip
spec:
ingressClassName: apisix
http:
- name: getting-started-ip
match:
paths:
- /ip
backends:
- serviceName: httpbin
servicePort: 80
Apply the configurations to your cluster:
kubectl apply -f httpbin-route.yaml
#
VerifyExpose the service port to your local machine by port forwarding:
kubectl port-forward svc/apisix-gateway 9080:80 &
Send a request to the Route:
curl "http://127.0.0.1:9080/ip"
You should see a response similar to the following:
{
"origin": "127.0.0.1"
}