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

Path based routing not working after upgrading nginx-ingress-controller from 0.19.0 to 0.22.0 #3762

Closed
dkirrane opened this issue Feb 13, 2019 · 5 comments

Comments

@dkirrane
Copy link

dkirrane commented Feb 13, 2019

Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT

NGINX Ingress controller version:
quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.22.0
helm install stable/nginx-ingress --version 1.3.0

Kubernetes version (use kubectl version):

Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-10T23:35:51Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-10T23:28:14Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration:
    CentOS bare metal - kubeadm v1.13.2 created cluster

  • OS (e.g. from /etc/os-release):

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
  • Kernel (e.g. uname -a):
    Linux prod-master1 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  • Install tools:

kubeadm version: &version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-10T23:33:30Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"linux/amd64"}
helm version
Client: &version.Version{SemVer:"v2.12.3", GitCommit:"eecf22f77df5f65c823aacd2dbd30ae6c65f186e", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.12.3", GitCommit:"eecf22f77df5f65c823aacd2dbd30ae6c65f186e", GitTreeState:"clean"}

What happened:
Path based routing no longer works after upgrading from nginx-ingress-controller from 0.19.0 to 0.22.0

What you expected to happen:
Backwards compatibility

How to reproduce it (as minimally and precisely as possible):
Deployed Kubernetes Helm chart with Ingress path /dashboard

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/configuration-snippet: rewrite ^(/dashboard)$ $1 permanent;
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  rules:
  - host: my.domain.com
    http:
      paths:
      - backend:
          serviceName: kubernetes-dashboard
          servicePort: 443
        path: /dashboard
  tls:
  - hosts:
    - my.domain.com
    secretName: my-tls
@dkirrane dkirrane changed the title Path based routing not working after upgrading to stable/nginx-ingress version 1.3.0 Path based routing not working after upgrading from nginx-ingress-controller from 0.19.0 to 0.22.0 Feb 13, 2019
@aledbf
Copy link
Member

aledbf commented Feb 13, 2019

@dkirrane please check https://github.com/kubernetes/ingress-nginx/releases/tag/nginx-0.22.0 (Breaking changes section about rewrites)

@dkirrane dkirrane changed the title Path based routing not working after upgrading from nginx-ingress-controller from 0.19.0 to 0.22.0 Path based routing not working after upgrading from nginx-ingress-controller from 0.19.0 to 0.22.0 Feb 13, 2019
@dkirrane dkirrane changed the title Path based routing not working after upgrading from nginx-ingress-controller from 0.19.0 to 0.22.0 Path based routing not working after upgrading nginx-ingress-controller from 0.19.0 to 0.22.0 Feb 13, 2019
@dkirrane
Copy link
Author

@aledbf thanks working now.

For Kubernetes Dashboard Ingress.yaml I needed to change these annotations:

From:

    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: "/"
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: rewrite ^(/dashboard)$ $1/ permanent;
...
  paths:
    - /dashboard

To :

    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
...
  paths:
    - /dashboard/?(.*)

@kadian2010
Copy link

kadian2010 commented Jul 6, 2019

You should to add
nginx.ingress.kubernetes.io/rewrite-target: /$1
path: /ashok/?(.*)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: techhearts
  namespace: techhearts
  annotations:
    kubernetes.io/ingress.class: nginx-techhearts
    kubernetes.io/tls-acme: "true"
    ingress.kubernetes.io/force-ssl-redirect: "true"
    certmanager.k8s.io/cluster-issuer: letsencrypt-production
    certmanager.k8s.io/acme-challenge-type: dns01
    certmanager.k8s.io/acme-dns01-provider: prod-dns
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: techhearts.com
      http:
        paths:
          - path: /ashok/?(.*)
            backend:
              serviceName: techhearts-app
              servicePort: 80
  tls:
    - hosts:
        - techhearts.com
      secretName: abc-tls

After deploying it. you can able to reach techhearts.com/ashok/index.html

@vishaltak
Copy link

Do refer comment
Basically, use path: /abc(/|$)(.*) and rewrite-target: /$2 instead of /abc/?.* and rewrite-target: /$1 to avoid extra matching of characters and cause unexpected redirections.

@indamutsa
Copy link

I spend literally a day with this problem. The problem was simply the wrong nginx installed. I used helm found here to install nginx-ingress

Install it, please use helm version 3:

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

helm install ingress-nginx ingress-nginx/ingress-nginx

Once run, in the logs you shall see a snippet that illustrates how your ingress should look like. In case you want to do the above, you can the annotation suggested above and henceforth, you can follow tutorials here to achieve more such as rewrite.

My cluster is deployed on GCP using GKE

when done, this is the output log:

NAME: ingress-nginx
LAST DEPLOYED: Sat Apr 24 07:56:11 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The ingress-nginx controller has been installed.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl --namespace default get services -o wide -w ingress-nginx-controller'

An example Ingress that makes use of the controller:

  apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    annotations:
      kubernetes.io/ingress.class: nginx
    name: example
    namespace: foo
  spec:
    rules:
      - host: www.example.com
        http:
          paths:
            - backend:
                serviceName: exampleService
                servicePort: 80
              path: /
    # This section is only required if TLS is to be enabled for the Ingress
    tls:
        - hosts:
            - www.example.com
          secretName: example-tls

If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:

  apiVersion: v1
  kind: Secret
  metadata:
    name: example-tls
    namespace: foo
  data:
    tls.crt: <base64 encoded cert>
    tls.key: <base64 encoded key>
  type: kubernetes.io/tls

This is how my ingress looks like now after installing it:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2

  name: example
  # namespace: foo
spec:
  rules:
    - host: [your ip address].xip.io
      http:
        paths:
          - backend:
              serviceName: registry-app-server
              servicePort: 8761
            path: /eureka
          - backend:
              serviceName: api-gateway-server
              servicePort: 7000
            path: /api(/|$)(.*)

When i hit [your ip address].xip.io/eureka , it will rewrite and redirect to the service with route as / which returns the eureka registry

When i hit [your ip address].xip.io/api/test/hello , it will rewrite and redirect to the service with route as /test/hello this returns the data as configured in microservices using spring api gateway.

As you can see I am deploying spring micro-services using kubernetes(gke).
There are a lot of benefits of using nginx-ingress over built-in gke ingress, and it is more popular than its counterparts

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

5 participants