We hosted a website in AWS Kubernetes Service. niginx-ingress-path issue

2/7/2020

We hosted a website in AWS Kubernetes Service. We are having following issue.
issue1.css not working issue2:Redirection also not working

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: myapp1-alerts-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"    
    cert-manager.io/issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/rewrite-target: "/"

spec:
  tls:
  - hosts:
    - dev-api.myapp1.solutions
    secretName: myapp1-alerts-tls
  rules:
  - host: dev-api.myapp1.solutions
    http:
      paths:
      - path: /alerts
        backend:
          serviceName: myapp1-alerts
          servicePort: 80

enter image description here

-- user3926919
eks
kubernetes
kubernetes-ingress
nginx

1 Answer

2/17/2020

Take a look at the official documentation. There you will find an example below:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)
  | kubectl create -f -

In this ingress definition, any characters captured by (.*) will be assigned to the placeholder $2, which is then used as a parameter in the rewrite-target annotation.

For example, the ingress definition above will result in the following rewrites:

  • rewrite.bar.com/something rewrites to rewrite.bar.com/

  • rewrite.bar.com/something/ rewrites to rewrite.bar.com/

  • rewrite.bar.com/something/new rewrites to rewrite.bar.com/new

Adjust your config accordingly and please let me know if that helped.

-- OhHiMark
Source: StackOverflow