Proxy Requests to a Service
This tutorial shows you how to create a basic route with the Ingress Controller that proxies requests to a sample service running in the cluster and verify that the routing functions correctly.
Prerequisite
- Complete Set Up Ingress Controller and Gateway.
Start a Sample Upstream Service
Start an HTTPBIN service named httpbin in the current namespace to use as the sample upstream service:
kubectl apply -f https://raw.githubusercontent.com/apache/apisix-ingress-controller/refs/heads/v2.0.0/examples/httpbin/deployment.yaml
Create a Route
Create a Kubernetes manifest file for a route that will proxy requests to the HTTPBIN sample upstream service:
- Gateway API
- Ingress
- APISIX CRD
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: aic
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:
namespace: aic
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:
namespace: aic
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
Verify Routing
Expose the gateway’s service port to your local machine:
# replace with your gateway’s service name
kubectl port-forward svc/<gateway-service-name> 9080:80 &
Send a request to the route:
curl "http://127.0.0.1:9080/ip"
You should see a response of the following:
{
"origin": "127.0.0.1"
}
Delete the Route
To remove the previously created route, run the following command:
kubectl delete -f httpbin-route.yaml
Next Steps
You have now learned the basics of proxying requests with a route. Next, you will explore the broader capabilities provided by the plugin ecosystem.