Can keycloak service work with ingress rewrite-target rules in k8s?

Viewed 154

My task is create ingress rules between some services in k8s, one of this - keycloak. I try to write rule for it as:

my-service.my-url.com/keycloak

My ingress.yaml:

kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: my-ing
  namespace: my-ns
spec:
  rules:
  - host: my-service.my-url.com
    http:
      paths:
#to keycloak 
      - path: /keycloak(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: keycloak
            port:
              number: 8090
# all other url
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-main-service
            port:
              number: 8080

But keycloak service rewrite my url with /auth as

my-service.my-url.com/auth

... and after this my ingress rules send url to main service that return error!

If change rules with /auth as...

#to keycloak 
      - path: /auth(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: keycloak
            port:
              number: 8090
# all other url
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-main-service
            port:
              number: 8080

i will take recurse error: ingress remove "/auth", keycloak add it again, ingress remove and etc...

Is the any way to resolve this task? I check this rule:

 rules:
  - host: my-service.my-url.com
    http:
******
  - host: my-keycloak.my-url.com
    http:
******

... it's work, but not for my situation.

Also i try to change Front url setup in keycloak realm: change keycloak setup

but it create other problem:

error responce from keycloak

And now i have no idea for this problem...

Can someone help with this?

Thnx.

0 Answers
Related