Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove routing path from Kubernetes ingress

I deployed service called "test" in kubernetes. service name : test port : 80

There is endpoint called "/abc"

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: load-balancer

spec:
  rules:
  - http:
      paths:
      - path: /test/*
        backend:
          serviceName: test
          servicePort: 80

API call "http://ip-address/test/abc" given 404 error. But endpoint "/test/abc" working properly.

I need skip "/test" when routing. How I do this.

like image 638
Nuwan Sameera Avatar asked Oct 22 '18 06:10

Nuwan Sameera


People also ask

What is rewrite target in ingress?

In this ingress definition, any characters captured by (. *) will be assigned to the placeholder $2 , which is then used as a parameter in the rewrite-target annotation. For example, the ingress definition above will result in the following rewrites: rewrite.bar.com/something rewrites to rewrite.bar.com/

What is pathType in ingress?

A new pathType field that can specify how Ingress paths should be matched. A new IngressClass resource that can specify how Ingresses should be implemented by controllers. Support for wildcards in hostnames.


2 Answers

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)

In this ingress definition, any characters captured by (.*) will be assigned to the placeholder $2, which is then used as a parameter in the rewrite-target annotation.

For example:

  • rewrite.bar.com/something rewrites to rewrite.bar.com/

Source: https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/rewrite/README.md.

like image 144
Constantin De La Roche Avatar answered Oct 17 '22 11:10

Constantin De La Roche


You're looking for url rewriting feature. It's currently only supported on nginx-ingress (not GKE ingress). https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/rewrite/README.md.

But you can install nginx-ingress controller on GKE if you want, there's documentation on how to do that.

like image 35
ahmet alp balkan Avatar answered Oct 17 '22 10:10

ahmet alp balkan