'kubernetes ingress service annotations

I am setting up an ingress service following some k8s documentation, but I am not able to understand the following annotations:

kubernetes.ip/ingress.class:

nginx.ingress.kubernetes.io/rewrite-target:

Do you know what these annotations do?

Thanks in advance.



Solution 1:[1]

  1. kubernetes.io/ingress.class annotation is officially deprecated:

Before the IngressClass resource was added in Kubernetes 1.18, a similar concept of Ingress class was often specified with a kubernetes.io/ingress.class annotation on the Ingress. Although this annotation was never formally defined, it was widely supported by Ingress controllers, and should now be considered formally deprecated.

Instead you should use the ingressClassName:

The newer ingressClassName field on Ingresses is a replacement for that annotation, but is not a direct equivalent. While the annotation was generally used to reference the name of the Ingress controller that should implement the Ingress, the field is a reference to an IngressClass resource that contains additional Ingress configuration, including the name of the Ingress controller.

  1. The rewrite annotation does as follows:

In some scenarios the exposed URL in the backend service differs from the specified path in the Ingress rule. Without a rewrite any request will return 404. Set the annotation nginx.ingress.kubernetes.io/rewrite-target to the path expected by the service.

If the Application Root is exposed in a different path and needs to be redirected, set the annotation nginx.ingress.kubernetes.io/app-root to redirect requests for /.

For a more detailed example I strongly suggest you can check out this source. It shows exactly how rewriting works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wytrzymały Wiktor