Interview Prep/Kubernetes/Services, DNS, Ingress and NetworkPolicy

After adding `rewrite-target: /`, the app home page loads but CSS and JS return 404.

IntermediateTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer

Likely causes → A path /shop with rewrite-target: / rewrites every request to /, so /shop/static/app.css also becomes /. Or the app emits absolute links (/static/...) that skip the /shop prefix.

Diagnose →

kubectl get ingress shop -o yaml | yq '.metadata.annotations, .spec.rules'
curl -s https://example.com/shop/ | grep -Eo '(src|href)="[^"]+"' | head

Fix → Use capture groups so the remainder of the path is kept:

annotations:
  nginx.ingress.kubernetes.io/use-regex: "true"
  nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - http:
        paths:
          - path: /shop(/|$)(.*)
            pathType: ImplementationSpecific
            backend: {service: {name: shop, port: {number: 80}}}

And configure the app's base path so it emits /shop/static/....

Prevent → Prefer host-based routing per app over path prefixes when apps are not prefix-aware.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, DNS, Ingress and NetworkPolicy