Forum Discussion
How to rewrite a path to a backend service dropping the prefix and passing the remaining path?
Hello xuwen & JRahm,
Thank you fo your quick responses and help. After a break, I adjusted the path, as below, and was able to successfully route to httpbin and preserve the path after the prefix. Hopefully, this will help others... 🙂
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mikie-ingress
namespace: mikie
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
ingressClassName: nginx
rules:
- host: abczzz.com
http:
paths:
- backend:
service:
name: httpbin-service
port:
number: 8999
path: /httpbin/(.*)
pathType: Prefix
In order to compare my issues, I deployed nginx-ingress, which we will be using for our deployment, and the community edition, to two separate Kubernetes clusters. When I reported success a few minutes ago, it was with the community edition. However, with nginx-ingress and the same manifests used for the community edition, the rewrites are not succeeding... 404s... Arggg...
I've attached my deployment scripts, which I was documenting for our team. Could you please take a look at them to see whether you spot any reasons that they wouldn't work, as expected? I am going to dig back in when I get back into the office in the morning and will report what I find. I've left the httpbin backend services running, in case you want to play with anything. No issues with your access, if desired.
Thank you for your help and support,
Mike
- JRahmJun 03, 2022Admin
I'll try to track down some help for you, michaelgardner. In the meantime, can you clarify if you are using the kuburnetes flavor of nginx ingress, or the nginx ingress for kubernetes? Clear as mud, I know...this might help: https://www.nginx.com/blog/guide-to-choosing-ingress-controller-part-4-nginx-ingress-controller-options/.
Examples of rewrites from the nginx ingress BY nginx: https://github.com/nginxinc/kubernetes-ingress/tree/v2.2.2/examples/rewrites- JRahmJun 03, 2022Admin
ok, maybe you're using the kubernetes version of the nginx ingress instead of the nginx version of the nginx ingress. Give a read-through on that article I linked and take a look at the examples. Not telling you which version to use, but the expertise around here will be more geared toward the nginx version.
- michaelgardnerJun 03, 2022Altocumulus
Hi, Actually, I have both deployed to separate Kubernetes clusters at Digital Ocean... One cluster has the community version of nginx (aboh-cluster) and the other cluster (abitofhelp-cluster) has nginx.com. In both cases, I've deployed the ingress. For the community version, I used DigitalOceans "MarketPlace" installer. For the commercial version, I installed using the helm chart without any alterations.
The use case that I've shown is such a common one, that having this discussion in one location with the same set of manifests configuring the deployment/service and ingress for the commercial and community editions will be very helpful for others. Although nginx is very popular and stable, which is a good thing, the downside is that there is a lot of incorrect and out-of-date information on the Net.
I am going to repeat my tests today and may start over with fresh deployments of everything, but use the manifests that I have shared since they worked in my previous testing on the community version. In the commercial installation, there were no customizations made. In the community installation, I'd have to dig into DigitalOcean's scripting or contact them for details. I'd expect that they are plain-jane since they could have such a large variety of users of the service.
I agree that things get a bit cloudy, sometimes... commercial... community... ingress... VMs... standalone... Arggggg! Thankfully, nginx is a stable product with a lot of interested supporters.
Thank you for any help that you can provide. If any of this is falling outside of the boundaries of this forum, please let me know and we can drop the investigation here.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com