nginxinc / kubernetes-ingress

NGINX and NGINX Plus Ingress Controllers for Kubernetes
https://docs.nginx.com/nginx-ingress-controller
Apache License 2.0
4.65k stars 1.96k forks source link

Multiple redirects not working #877

Closed kumargauravin closed 4 years ago

kumargauravin commented 4 years ago

I tried the plus option for enabling rewrite per path, does not seem to work. Created basic from helm install nginx-ingress-plus stable/nginx-ingress --namespace ingress-plus --set controller.replicaCount=2 --set controller.nodeSelector."beta.kubernetes.io/os"=linux --set defaultBackend.nodeSelector."beta.kubernetes.io/os"=linux --set controller.nginxplus=true

calls from daasdemoserverservice still rewrites to / in place of /serv/

Config for ingress below: { "kind": "Ingress", "apiVersion": "extensions/v1beta1", "metadata": { "name": "ingress-plus-option", "namespace": "ingress-plus", "selfLink": "/apis/extensions/v1beta1/namespaces/ingress-plus/ingresses/ingress-plus-option", "generation": 8, "creationTimestamp": "2020-03-07T20:07:36Z", "annotations": { "nginx.org/rewrites": "serviceName=uitestservice rewrite=/;serviceName=daasdemoserverservice rewrite=/serv/;" } }, "spec": { "rules": [ { "http": { "paths": [ { "path": "/", "backend": { "serviceName": "uitestservice", "servicePort": 8080 } }, { "path": "/serv/", "backend": { "serviceName": "daasdemoserverservice", "servicePort": 80 } } ] } } ] }, "status": { "loadBalancer": { "ingress": [ { }, { } ] } } }

pleshakov commented 4 years ago

Hi @kumargauravin

I noticed a few problems in your Ingress resource.

(1) The IC expects that the host field of an Ingress resource must be configured. Please add the host field.

(2) Could you remove the trailing ; from the annotation, so it looks like this?

"nginx.org/rewrites": "serviceName=uitestservice rewrite=/;serviceName=daasdemoserverservice rewrite=/serv/"

The parser of annotations is a bit sensitive. Otherwise, you would get an error in the logs that looks like below:

E0309 15:23:41.558756       1 annotations.go:332] In cafe-ingress nginx.org/rewrites contains invalid declaration: Invalid rewrite format: , ignoring

(3) Additionally, could you possibly clarify what rewrite would you like to configure? The rewrite annotation that you shared will not perform any rewrite.

To make sure that the IC successfully applied the Ingress configuration, make sure to check the events of the Ingress resource. See https://docs.nginx.com/nginx-ingress-controller/troubleshooting/#checking-the-events-of-an-ingress-resource

kumargauravin commented 4 years ago

Hi

Thanks for reply but we later checked that using ingress plus is commercial right ? So we have not tried after that.

If we can use ingress plus like open source let me know please.

Regards, Kumar

On Mon, Mar 9, 2020 at 10:40 AM Michael Pleshakov notifications@github.com wrote:

Hi @kumargauravin https://github.com/kumargauravin

I noticed a few problems in your Ingress resource.

(1) The IC expects that the host field of an Ingress resource must be configured. Please add the host field.

(2) Could you remove the trailing ; from the annotation, so it looks like this?

"nginx.org/rewrites": "serviceName=uitestservice rewrite=/;serviceName=daasdemoserverservice rewrite=/serv/"

The parser of annotations is a bit sensitive. Otherwise, you would get an error in the logs that looks like below:

E0309 15:23:41.558756 1 annotations.go:332] In cafe-ingress nginx.org/rewrites contains invalid declaration: Invalid rewrite format: , ignoring

(3) Additionally, could you possibly clarify what rewrite would you like to configure? The rewrite annotation that you shared will not perform any rewrite.

To make sure that the IC successfully applied the Ingress configuration, make sure to check the events of the Ingress resource. See https://docs.nginx.com/nginx-ingress-controller/troubleshooting/#checking-the-events-of-an-ingress-resource

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nginxinc/kubernetes-ingress/issues/877?email_source=notifications&email_token=ADK64R2VXJPXM7GJGD5EHSTRGULWTA5CNFSM4LDS3VS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOHYACI#issuecomment-596606985, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADK64R6G2XHTS2HWTVAILNLRGULWTANCNFSM4LDS3VSQ .

pleshakov commented 4 years ago

Hi @kumargauravin,

Correct, NGINX Plus is a commercial version.

Our Ingress Controller supports both NGINX and NGINX Plus.

The feature in question is available when you use either NGINX or NGINX Plus. In our docs https://docs.nginx.com/nginx-ingress-controller/, most of the features are available both in NGINX and NGINX Plus, unless we specifically mention that NGINX Plus is required.

kumargauravin commented 4 years ago

Hi,

So last question ability to rewrite to different base is something included in free version or not since that is something I was not able to get working.

Also having troubles with not able to connect with ACRs during image pull and your router override in Kube System keep on saying timeout in token refresh. Not sure what to do.

Regards, Kumar

On Mon, Mar 16, 2020 at 11:28 AM Michael Pleshakov notifications@github.com wrote:

Hi @kumargauravin https://github.com/kumargauravin,

Correct, NGINX Plus is a commercial version.

Our Ingress Controller supports both NGINX and NGINX Plus.

The feature in question is available when you use either NGINX or NGINX Plus. In our docs https://docs.nginx.com/nginx-ingress-controller/, most of the features are available both in NGINX and NGINX Plus, unless we specifically mention that NGINX Plus is required.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nginxinc/kubernetes-ingress/issues/877#issuecomment-599632137, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADK64RZ27UMZBYK7EEVS2FTRHZHUPANCNFSM4LDS3VSQ .

pleshakov commented 4 years ago

Hi @kumargauravin

So last question ability to rewrite to different base is something included in free version or not since that is something I was not able to get working.

this feature is included in the free version

Also having troubles with not able to connect with ACRs during image pull and your router override in Kube System keep on saying timeout in token refres

I am not sure I can help you with problems with ACR. However, please note that the OSS (free) version of the Ingress Controller is available through DockerHub https://hub.docker.com/r/nginx/nginx-ingress . Latest stable release : nginx/nginx-ingress:1.6.3 or nginx/nginx-ingress:1.6.3-alpine

kumargauravin commented 4 years ago

Gr8, solved the other problem, some issue with DNS setup. Sorry to bother you. For if its included in free version like different rewrite per service name, can you share anything I need to different from installing normal ingress and a sample of config which should work for me?

On Tue, Mar 17, 2020 at 4:20 PM Michael Pleshakov notifications@github.com wrote:

Hi @kumargauravin https://github.com/kumargauravin

So last question ability to rewrite to different base is something included in free version or not since that is something I was not able to get working.

this feature is included in the free version

Also having troubles with not able to connect with ACRs during image pull and your router override in Kube System keep on saying timeout in token refres

I am not sure I can help you with problems with ACR. However, please note that the OSS (free) version of the Ingress Controller is available through DockerHub https://hub.docker.com/r/nginx/nginx-ingress . Latest stable release : nginx/nginx-ingress:1.6.3 or nginx/nginx-ingress:1.6.3-alpine

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nginxinc/kubernetes-ingress/issues/877#issuecomment-600307204, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADK64RZKULUNGVMTEAYJFOTRH7STJANCNFSM4LDS3VSQ .

pleshakov commented 4 years ago

Hi @kumargauravin

Glad you solved the problem with DNS!

can you share anything I need to different from installing normal ingress and a sample of config which should work for me

This would depend on the rewrites you want to perform. This page https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/rewrites shows a few examples of rewrites and how to configure them using the annotation.

kumargauravin commented 4 years ago

Last thing. I am able to use that notation. But following your instructions and example what is beans? Like how do I know which path to redirect.

Setup: One Flask API with Swagger UI at path /api One Angular Front end at path /

If service name for UI is uiapp and api is service that how I should write my rule with annotation?

What path I can give as redirect so that swagger.json and css js files load correctly from correct context.

Also, if a path is not found it gives 200 with /index.html as data of the response how I can resolve it?

Regards, Kumar

On Mon, Mar 23, 2020 at 12:14 PM Michael Pleshakov notifications@github.com wrote:

Hi @kumargauravin https://github.com/kumargauravin

Glad you solved the problem with DNS!

can you share anything I need to different from installing normal ingress and a sample of config which should work for me

This would depend on the rewrites you want to perform. This page https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/rewrites shows a few examples of rewrites and how to configure them using the annotation.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nginxinc/kubernetes-ingress/issues/877#issuecomment-602737065, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADK64R4JZDNSVUWDPWDIRNTRI6KIZANCNFSM4LDS3VSQ .

pleshakov commented 4 years ago

Hi @kumargauravin

Not sure if I completely understand your requirements.

Could you provide an example of an Ingress resource without rewrite annotations?

And also the requirements for rewrites. For example, for path "/foo", requests like "/foo/something" must be rewritten to "/something" before NGINX sends them to the backend.

kumargauravin commented 4 years ago

The problem is the relative path. Say angular application has a path /ui so /ui/index.html rewrites to /index.html but the files like css and js dependencies also goto / path and download index.html only but in name of css and js files which does not load the application. Similarly say API at path/api rewrites to / path but it’s swagger.json and js, css dependencies are again not available at /.

Regards, Kumar Gaurav

On Tue, Mar 31, 2020 at 6:20 PM Michael Pleshakov notifications@github.com wrote:

Hi @kumargauravin https://github.com/kumargauravin

Not sure if I completely understand your requirements.

Could you provide an example of an Ingress resource without rewrite annotations?

And also the requirements for rewrites. For example, for path "/foo", requests like "/foo/something" must be rewritten to "/something" before NGINX sends them to the backend.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nginxinc/kubernetes-ingress/issues/877#issuecomment-606935986, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADK64R3WASIGQOOVQAFBX6LRKJ3CZANCNFSM4LDS3VSQ .

-- Regards, Kumar Gaurav +1 469 354 2101

pleshakov commented 4 years ago

@kumargauravin Is it possible to change your backend application(s) or make its base path configurable, so that no rewriting is required by the Ingress Controller?

I must add that NGINX can modify responses, so that it is possible to update paths in html or other files files by using the sub_filter module. However, It is not directly available in the Ingress Controller, but you can use it through snippets. However, those rules might get complex to configure.

kumargauravin commented 4 years ago

Sure will give both a try.

But please take as a feedback and get some feature since from devops point of view, I should be able to provide a context to application in a way that /dependency.extension should rewrite to server as /context/dependency.extension. Right! I am also new to all this specially using k8s with Azure. So do not mind if I am saying something wrong, Consider it my inexperience and guide me please.

Regards, Kumar

On Fri, Apr 3, 2020 at 5:14 PM Michael Pleshakov notifications@github.com wrote:

@kumargauravin https://github.com/kumargauravin Is it possible to change your backend application(s) or make its base path configurable, so that no rewriting is required by the Ingress Controller?

I must add that NGINX can modify responses, so that it is possible to update paths in html or other files files by using the sub_filter module http://nginx.org/en/docs/http/ngx_http_sub_module.html. However, It is not directly available in the Ingress Controller, but you can use it through snippets https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/#snippets-and-custom-templates. However, those rules might get complex to configure.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nginxinc/kubernetes-ingress/issues/877#issuecomment-608711764, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADK64RYX4SJ2NBETT2CYGSDRKZNUNANCNFSM4LDS3VSQ .

-- Regards, Kumar Gaurav +1 469 354 2101