I use Traefik IngressRoute in Kubernetes.
My goal is to proxy a request when accessing https://kubernetes_host.com/my_api/… to http://10.139.158.30:5000/api/v1/
I would do this in Nginx:
location /my_api {
proxy_pass http://10.139.158.30:5000/api/v1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme http;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
But I can’t figure out how to do this in Traefik IngressRoute.
In the documentation, proxying requests only for internal Kubernetes services.
Example:
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: route-proxy
namespace: xxx
spec:
entryPoints:
- xxx
routes:
- kind: Rule
match: PathPrefix(`/my_api`)
services:
- kind: Service
name: some-service
port: 80
Best Answer
You can try creating an
Endpoint
-Service
pair to point to your IP:Or using the newer
EndpointSlice
API (from k8s v1.21):Then, reference the
Service
in yourIngressRoute
definition:More information: https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors.