If I want to create an ingress with just a redirect and nothing else then I should be able to specify it like this:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-301
annotations:
kubernetes.io/ingress.class: nginx
ingress.kubernetes.io/permanent-redirect: http://to.example.com
spec:
rules:
- host: from.example.com
However this does not work and no redirect config is added. This is probably because of this:
controller.go:702] ingress rule default/example-301 does not contain HTTP rules, using default backend
If I add a dummy http path and backend then the redirect is added correctly.
Closing. This works as expected. You need a rule. Please keep in mind you can have multiple rules for the same hostname and different paths. This requirement makes sure you only get a redirect for the rule where the annotation is configured and not all the paths
Hello,
Could anybody provide a working example? We can't figure out how to use this.
Where is the rule supposed to be?
Thanks
Just in case anyone else lands in here, the correct annotation is now: nginx.ingress.kubernetes.io/permanent-redirect
This worked for me:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/permanent-redirect: "https://main.com"
name: main-alias
spec:
rules:
- host: alternate.com
http:
paths:
- backend:
serviceName: main
servicePort: 8080
tls:
- hosts:
- alternate.com
secretName: alternate-tls
The backend configuration seemed to be required for the redirect config to be picked up, even though it will never be used in this case. I also disabled the ssl redirect to prevent a double redirect.
Most helpful comment
This worked for me:
The backend configuration seemed to be required for the redirect config to be picked up, even though it will never be used in this case. I also disabled the ssl redirect to prevent a double redirect.