Kubernetes ingress with backend serviceName regex/wildcard or selector

2/4/2022

Hi all we have a Flink application with blue-green deployment which we get using the Flink operator.

Flinkk8soperator for Apache Flink. The operator spins up the following three K8s services after a deployment:

my-flinkapp-14hdhsr (Top level service)
my-flinkapp-green
my-flinkapp-blue

The idea is that one of the two among blue green would be active and would have pods (either blue or green).

And a selector to the the active one would be stored in the top level myflinkapp-14hdhsr service with the selector flink-application-version=blue. Or green. As follows:

Labels:  flink-app=my-flinkapp
         flink-app-hash=14hdhsr
         flink-application-version=blue
Annotations:       <none>
Selector:          flink-app=my-flinkapp,flink-application-version=blue,flink-deployment-type=jobmanager,

I have an ingress defined as follows which I want to use to point to the top level service.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header Accept-Encoding "";
      sub_filter '<head>' '<head> <base href="/happy-flink-ui/">';
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/auth-url: "https://$host/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://$host/oauth2/start?rd=$escaped_request_uri"
  name: flink-secure-ingress-my-flink-app
  namespace: happy-flink-flink
spec:
  rules:
    - host: flinkui-myapp.foo.com
      http:
        paths:
          - path: /happy-flink-ui(/|$)(.*)
            backend:
              serviceName: my-flinkapp-14hdhsr // This works but....
              servicePort: 8081

The issue I am facing is that the top level service keeps changing the hash at the end as the flink operator changes it at every deployment.. eg. myflinkapp-89hddew .etc.

So I cannot have a static service name in the ingress definition.

So I am wondering if an ingress can choose a service based on a selector or a regular expression of the service name which can account for the top level app service name plus the hash at the end.

The flink-app-hash (i.e the hash part of the service name - 14hdsr) is also part of the Labels in the top level service. Anyway I could leverage that?

Wondering if default backend could be applied here?

Have folks using Flink operator solved this a different way?

-- Ace McCloud
apache-flink
blue-green-deployment
kubernetes
kubernetes-ingress
kubernetes-service

1 Answer

2/7/2022

Unfortunately that's not possible OOB to use any kind of regex/wildcards/jsonpath/variables/references inside .backend.serviceName inside Ingres controller. You are able to use regex only in path: Ingress Path Matching

And its not going to be implemented soon: Allow variable references in backend spec is in the hanged stage.

Would be very interesting to hear any possible solution for this. It was previously discussed on stack, however without any progress: https://stackoverflow.com/a/60810435/9929015

-- Vit
Source: StackOverflow