I am using google clould, GKE.
I have this example ingress.yaml
:
1 apiVersion: extensions/v1beta1
2 kind: Ingress
3 metadata:
4 name: kuard
5 namespace: sample
6 annotations:
7 kubernetes.io/ingress.class: "nginx"
8 cert-manager.io/issuer: "letsencrypt-prod"
9 nginx.ingress.kubernetes.io/permanent-redirect: https://www.google.com
10 spec:
11 tls:
12 - hosts:
13 - example.gordion.io
14 secretName: quickstart-example-tls
15 rules:
16 - host: example.gordion.io
17 http:
18 paths:
19 - path: /
20 backend:
21 serviceName: kuard
22 servicePort: 80
I need that when user request specific host, like: example-2.gordion.io
, to be redirected to other site, outside the cluster, (on other google cluster actually), using nginx.
Currently I am aware only to the specific annonation nginx.ingress.kubernetes.io/permanent-redirect
which seems to be global. How is it possible to redirct based on specific requested host in this ingress file?
you combine an externalName service with another ingress file: In the following yaml file we define an ExternalName service with the name example-2.gordion.io-service
, which will lead to the real site service in the other cluster:
kind: Service
apiVersion: v1
metadata:
name: example-2.gordion.io-service
spec:
type: ExternalName
externalName: internal-name-of-example-2.gordion.io
And an ingress file to direct example-2.gordion.io
to example-2.gordion.io-service
:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: example-2.gordion.io
http:
paths:
- path: /
backend:
serviceName: example-2.gordion.io-service
servicePort: 80