add Rewrite Rules 301 in nginx ingress controller

4/7/2017

How to creating Rewrite Rules about nginx ingress controller, in the same way as NGINX able to do redirect.

like : (exemple) server_name www.foo.com; rewrite ^/search$ https://www.foo.com/all/search permanent;

-- Cyril CLEMENT
controller
kubernetes
nginx
url-rewriting

1 Answer

4/7/2017

This is supported in the latest (beta.3) version of the ingress controller.

You set it using annotations. Have a look at the example here

Essentially, when you set up your ingress, you'll need to specify it like so:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/rewrite-target: /search
  name: rewrite
  namespace: default
spec:
  rules:
  - host: foo.com
    http:
      paths:
      - backend:
          serviceName: my-service
          servicePort: 80
        path: /all/search
-- jaxxstorm
Source: StackOverflow