Skip to main content
Version: 0.4.0

ApisixRoute

ApisixRoute is a CRD resource which focus on how to route traffic to expected backend, it exposes many features supported by Apache APISIX. Compared to Ingress, functions are implemented in a more native way, with stronger semantics.

Path based route rules#

URI path are always used to split traffic, for instance, requests with host foo.com and /foo prefix should be routed to service foo while requests which path is /bar should be routed to service bar, in the manner of ApisixRoute, the configuration should be:

apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: foor-bar-route
spec:
http:
- name: foo
match:
hosts:
- foo.com
paths:
- "/foo*"
backend:
serviceName: foo
servicePort: 80
- name: bar
match:
paths:
- "/bar"
backend:
serviceName: bar
servicePort: 80

There are two path types can be used, prefix and exact, default is exact, while if prefix is desired, just append a *, for instance, /id/* matches all paths with the prefix of /id/.

Advanced route features#

Path based route are most common, but if it's not enough, try other route features in ApisixRoute such as methods, nginxVars.

The methods splits traffic according to the HTTP method, the following configurations routes requests with GET method to foo service (a Kubernetes Service).

apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: method-route
spec:
http:
- name: method
match:
paths:
- /
methods:
- GET
backend:
serviceName: foo
servicePort: 80

Service Resolution Granularity#

By default a referenced Service will be watched, so it's newest endpoints list can be updated to Apache APISIX. apisix-ingress-controller provides another mechanism that just use the ClusterIP of this service, if that's what you want, just set the resolveGranularity to service (default is endpoint).

apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: method-route
spec:
http:
- name: method
match:
paths:
- /*
methods:
- GET
backend:
serviceName: foo
servicePort: 80
resolveGranularity: service

Plugins#

Apache APISIX provides more than 40 plugins, which can be used in ApisixRoute. All configuration items are named same to the one in APISIX.

apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: httpbin-route
spec:
http:
- name: httpbin
match:
hosts:
- local.httpbin.org
paths:
- /*
backend:
serviceName: foo
servicePort: 80
plugins:
- name: cors
enable: true

The above configuration enables Cors plugin for requests which host is local.httpbin.org.