1

I’m setting up an environment in Google Cloud with an ingress and load balancers.

I know how to setup hosts and paths to it but I can't figure out how to setup when a user goes to a specific site http://example.com/ I want him to redirect to http://example.com/en.

Note:

  • http => https

  • / => /en

UPDATED

I added app-root: /en (but it doesn't do anything).

This is my current yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: gce
    kubernetes.io/ingress.global-static-ip-name: our-frontend-static-ip
    networking.gke.io/managed-certificates: example-certificate
    appgw.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/app-root: /en
  name: example-ingress
  namespace: default
spec:
  rules:
  - host: anotherexample.com
    http:
      paths:
      - backend:
          serviceName: anotherexample-service
          servicePort: 80
  - host: example.com
    http:
      paths:
      - path: /nl
        backend:
          serviceName: example-nl-service
          servicePort: 80
      - path: /en
        backend:
          serviceName: example-en-service
          servicePort: 80

So, there are 2 hosts in my yaml and I want: when the url is correct for 1 of the hosts: example.com it must go to example.com/en (this is for Multilanguage purposes)

We can change the settings in the loadbalancer ban after the sync from the ingress in changes it back.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37

1 Answers1

0

Kubernetes supports multiple Ingress Controllers which are different from each other. For example, you are trying to use the Ingress GCE and there is also a popular Nginx Ingress.

The main problem in your use case is that the Ingress GCE is not supporting rewrites. An on-going feature request regarding that can be found here.

To be able to use the rewrites you will need to deploy the Nginx Ingress Controller and switch annotation in your yaml from:

kubernetes.io/ingress.class: "gce"

to:

kubernetes.io/ingress.class: "nginx"

The sources that will help you out with this are as follows:

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
  • Sorry it took longer then expected to answer. So there is no way at the moment to do it with GCE? because In the UI I can setup everything. Only after the resync from the ingress it removes my changes. And I will try nginx later this week. (tried it yesterday but we almost whent down on production) – Ties Theunissen Jun 16 '21 at 09:23
  • Hello @TiesTheunissen. If you wish to solve your issue using rewrites than you cannot do it with `kubernetes.io/ingress.class: "gce"` and need to deploy another Ingress Controller like mentioned Nginx. Feel free to ask another question if you encounter any problems with it so it will be nice and clear for everyone who wishes to help you out. – Wytrzymały Wiktor Jun 16 '21 at 09:45