Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure ingress resource with different rewrite statements #2175

Closed
nullbeck opened this issue Mar 6, 2018 · 3 comments
Closed

Comments

@nullbeck
Copy link

nullbeck commented Mar 6, 2018

NGINX Ingress controller version:
nginx-ingress-controller:0.11.0
Kubernetes version (use kubectl version):

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"d2835416544f298c919e2ead3be3d0864b52323b", GitTreeState:"clean", BuildDate:"2018-02-07T12:22:21Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0+coreos.0", GitCommit:"a65654ef5b593ac19fbfaf33b1a1873c0320353b", GitTreeState:"clean", BuildDate:"2017-09-29T21:51:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration:
    alibaba cloud
  • OS (e.g. from /etc/os-release):
    CentOS Linux release 7.4.1708 (Core)
  • Kernel (e.g. uname -a):
    Linux crediton-k8s-01 3.10.0-693.17.1.el7.x86_64 Basic structure  #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools:
    k8s installed using kubespray

What happened:
We used ingress by nginxinc/kubernetes-ingress
nginxinc/kubernetes-ingress resource file was:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-com-ingress 
  namespace: test
  annotations:
    nginx.org/rewrites: "serviceName=a-service rewrite=/a;serviceName=b-service rewrite=/b;
spec:
  tls:
  - hosts:
    - test.com
    secretName: test-com-secret
  - hosts:
    - www.test.com
    secretName: test-com-secret
  rules:
  - host: test.com
    http:
      paths:
      - path: /v1/a
        backend:
          serviceName: a-service
          servicePort: 80
      - path: /v1/b
        backend:
          serviceName: b-service
          servicePort: 80

as result:

server {
  server_name test.com
  location /v1/a {
    proxy_pass http://a-service/a;
  }

  location /v1/b {
    proxy_pass http://b-service/b;
  }
}

But now we are going to implement ingress by kubernetes/ingress-nginx

How do we need to write kubernetes/ingress-nginx rewrite statements for different services(like below) with different contexts? Could anybody give us example? Thanks a lot.

What you expected to happen:

server {
  server_name test.com
  location /v1/a {
    proxy_pass http://a-service/a;
  }

  location /v1/b { 
    proxy_pass http://b-service/b;
  }
}

Anything else we need to know:
We have 100+ microservices. Before in nginxinc/kubernetes-ingress was used one ingress resource. But in kubernetes/ingress-nginx we could not configure the same, because in rewrite statements of annotations there is no any serviceName like in nginxinc/kubernetes-ingress.

@dcherniv
Copy link

dcherniv commented Mar 6, 2018

As per https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/rewrite/README.md
The assumption in ingress-nginx controller is to have one backend per ingress resource since the rewrite annotation applies to all backend services.

@nullbeck
Copy link
Author

nullbeck commented Mar 7, 2018

@dcherniv thanks
another question, how to realize rewrite statement below in kubernetes/ingress-nginx?
did not find any examples.

server {
  server_name test.com 
  location /v1/a {
    proxy_pass http://a-service/a;
  }

@nullbeck
Copy link
Author

nullbeck commented Mar 7, 2018

after changing
ingress.kubernetes.io/rewrite-target: /
to
nginx.ingress.kubernetes.io/rewrite-target: /
it works.
Thanks. Issue is closed

@nullbeck nullbeck closed this as completed Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants