I have an app set up which can be contacted via the service-IP, but not using the Ingress Rule.
Consider the following Ingress Manifest:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp
namespace: default
annotations:
kubernetes.io/ingress.class: public
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/rewrite-target: /$0
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
spec:
tls:
- secretName: letsencrypt-prod
hosts:
- my.host.net
rules:
- host: my.host.net
http:
paths:
- path: /myapp(/|$)(.*)
pathType: Prefix
backend:
service:
name: myapp
port:
number: 1234
The relevant service is up and running. Doing a curl 10.152.183.91/myapp/path/
with 10.152.183.91
being the service IP gives the desired result.
When I go through curl my.host.net/myapp/path/
however, I get a 308 Permanent Redirect
. Other apps on the same cluster are running as expected, so the cluster itself as well as nginx-ingress and CoreDNS are doing their job.
Where did I go wrong? Is the nginx.ingress.kubernetes.io/rewrite-target: /$0
wrong?
2
Answers
The problem was that I didn't even need to do any redirection, since my app was listening to the endpoint
/myapp/
anyways. So any request hitting my server at the/myapp/path
already had the correct URL.I figured this out when
curl -L
showed a redirect loop (as pointed out by @dawik-kruk)First and foremost, you will need to change the:
nginx.ingress.kubernetes.io/rewrite-target: /$0
nginx.ingress.kubernetes.io/rewrite-target: /$2
Explanation:
As for the
curl
part. By running exactly the same as you did:curl my.host.net/myapp/path/
You will receive a
308 Permanent Redirect
.curl
by default is not following the redirection. Try withcurl -L
.Example with setup similar to yours: