This message was deleted.
# general
a
This message was deleted.
p
Using an ingress for rewriting rules is very inadapted. if you with to use an automatic load balancer, i've acheived something sililar with apache
Copy code
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Original-URL expr=%{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteRule ^/([^/]+)/(.*)$ http://%1/$2 [P,QSA,L]
Retirecting http://domain.com/foo/bar to http://foo/bar internally It works-ish but caused a whole lot of issues
r
sorry isn't possible to use load balancer apache, and really don't understand, just need to adapte the ingress only
p
then try this (untested) :
Copy code
apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    <http://nginx.ingress.kubernetes.io/rewrite-target|nginx.ingress.kubernetes.io/rewrite-target>: /$2
    <http://nginx.ingress.kubernetes.io/use-regex|nginx.ingress.kubernetes.io/use-regex>: "true"
spec:
  rules:
  - http:
      paths:
      - path: /([^/]+)/(.+)
        pathType: Prefix
        backend:
          service:
            name: $1
            port:
              number: 80
r
yes but I don't want that the webbrowser will redirect to http://foo/bar but kept on http://website/foo/bar but send request to the pod at /foo/bar
p
Thats not what will happen
r
we use that for the moment apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: meta.helm.sh/release-name: simenv meta.helm.sh/release-namespace: simenv nginx.ingress.kubernetes.io/add-base-url: "true" nginx.ingress.kubernetes.io/backend-protocol: HTTP nginx.ingress.kubernetes.io/configuration-snippet: | proxy_set_header Accept-Encoding ""; # sub_filter needs disabled compression sub_filter_once on; sub_filter '<base href="/env-rest-api"' '<base href="/mourmelon/"'; nginx.ingress.kubernetes.io/enable-rewrite-log: "true" nginx.ingress.kubernetes.io/rewrite-target: /env-rest-api/$1 nginx.ingress.kubernetes.io/ssl-passthrough: "true" nginx.ingress.kubernetes.io/use-regex: "true" creationTimestamp: "2024-05-07T091721Z" generation: 1 labels: app.kubernetes.io/managed-by: Helm name: env-api-ingress-mourmelon namespace: simenv resourceVersion: "5321396" uid: 96c4041b-a2ab-45b1-972e-f2753b347983 spec: ingressClassName: nginx rules: - http: paths: - backend: service: name: simenv-env-api-service-mourmelon port: number: 12001 path: /mourmelon/env-rest-api/(.*) pathType: ImplementationSpecific status: loadBalancer: ingress: - ip: 10.11.2.44
p
The rewrite would be internally i think
Yeah the rewrite is just for the internal request
"When a user accesses
<http://mysite.com/app1/geo|mysite.com/app1/geo>
, the request will be internally redirected to
<http://app1/geo>
within the Kubernetes cluster, but the URL in the browser will still display
<http://mysite.com/app1/geo|mysite.com/app1/geo>
. This is achieved through the use of the Nginx rewrite rules which modify the path that is sent to the backend service without changing the path shown in the browser's address bar."
(quoting chatgpt)