2

I had a Kibana that was previously running behind the NGINX ingress controller using this Ingress configuration:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: es-kibana-ing
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - host: "example.com"
      http:
        paths:
          - path: /kibana(/|$)(.*)
            pathType: Prefix
            backend:
              serviceName: es-kibana-svc
              servicePort: 443
  tls: 
    - hosts:
      - example.com
      secretName: example-tls

With this configuration you had to go to www.example.com/kibana to access the kibana. Since then we migrated to GCP and now I'm trying to achieve the same using the GCE ingress controller. For now I figured how to serve the kibana on path "/*" :

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: es-kibana-ing
  annotations:
    kubernetes.io/ingress.class: gce
    kubernetes.io/ingress.global-static-ip-name: kibana-static-ip
    networking.gke.io/managed-certificates: managed-cert
spec:
  rules:
    - host: "example.com"
      http:
        paths:
          - path: /*
            pathType: ImplementationSpecific
            backend:
              service:
                name: es-kibana-svc
                port:
                  number: 443

Instead I would like to serve the Kibana on the /kibana (as in the previous Nginx configuration), but I can't find an equivalent to rewrite-target for the gce controller. Any idea how this can be done?

Mit94
  • 718
  • 8
  • 28
  • Could you advise what exactly you want to do? In `GCP` you can enforce using `Nginx Ingress` by adding `kubernetes.io/ingress.class: "nginx"` to annotations and then all Nginx Ingress features (like rewrite and many more) works normally. `GCE Ingress` didn't have many features in comparison to nginx ingress. Do you have ELK or you just want to expose Kibana? Also are you using GKE cluster or GCE VMs to use Kubeadm or Minikube? – PjoterS Feb 08 '22 at 09:29
  • @PjoterS I'm using GKE cluster. Along Kibana I have many other applications, that's why I don't want to access Kibana through '/' but through '/kibana' so I can distringuish each application relatively to its path. I just want to replicate the behavior that I described for Nginx Ingress, that was allowing me to access my application through '/kibana' using the rewrite-target feature. If thats not possible in GCE I will revert to Nginx. – Mit94 Feb 08 '22 at 09:42

2 Answers2

2

If I understand what you want to achieve, you cannot do this using GCE Ingress, you would need to enforce Nginx Ingress.

Rewrite behavior of Nginx Ingress cannot be replicated by GCE Ingress. As I mentioned in the comment section, Nginx Ingress contains much more features than GCE Ingress, for example rewrite/capture groups or service type requirement (NodePort in GCE, ClusterIP or NodePort in Nginx).

With GCE Ingress you can achieve some static path rules like in this example. Something like that:

  rules:
    - http:
        paths:
        - path: /hello
          backend:
            serviceName: hello-svc
            servicePort: 8080
        - path: /hello-v2
          backend:
            serviceName: hello-v2-svc
            servicePort: 8080
        - path: /kibana
          backend:
            serviceName: kibana
            servicePort: 443
        - path: /randomsvc
          backend:
            serviceName: randomsvc
            servicePort: 8080

However, as I understand by your comment:

I just want to replicate the behavior that I described for Nginx Ingress, that was allowing me to access my application through '/kibana' using the rewrite-target feature.

Rewrite behavior is specific which cannot be replicated on GCE Ingress. There is a request to add a rewrite feature to GCE Ingress since 2018 but it's still open. More details about it you can find here.

You can find some differences between both Ingress in this guide.

PjoterS
  • 12,841
  • 1
  • 22
  • 54
0

It seems you may be using a different NGINX ingress controller and therefore annotations don't work as expected. You may find explanation of differences here.

Plus this closed GitHub issue seems to be very similar to yours so hopefully you can try using the solution mentioned there.

  • 1
    I was actually refering to the community version of the Nginx controller: https://kubernetes.github.io/ingress-nginx – Mit94 Feb 07 '22 at 20:15