Hello everyone,
i would like to use the /addprefix middleware in a k8s cluster.
My traefik install is on latest version mit helm-install.
Required CRDs and RBACs are installed like described in here: Kubernetes IngressRoute & Traefik CRD - Traefik
If i try to apply this:
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: nodered-ui-prefix
spec:
addprefix:
prefix:
- /ui
I just get this error:
error: error validating "middleware_addprefix.yaml": error validating data: ValidationError(Middleware.spec): unknown field "addprefix" in io.traefik.v1alpha1.Middleware.spec; if you choose to ignore these errors, turn validation off with --validate=false
The Middleware HTTP Docs also say that it's needed to install the middleware CRD Traefik Proxy HTTP Middleware Overview - Traefik
# As a Kubernetes Traefik IngressRoute
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: middlewares.traefik.io
spec:
group: traefik.io
version: v1alpha1
names:
kind: Middleware
plural: middlewares
singular: middleware
scope: Namespaced
Which give that error:
error: error validating "middlewares_CRD.yaml": error validating data: [ValidationError(CustomResourceDefinition.spec): unknown field "version" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec, ValidationError(CustomResourceDefinition.spec): missing required field "versions" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec]; if you choose to ignore these errors, turn validation off with --validate=false
But if i describe my CustomResourceDefinition the addprefix is already there:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: middlewares.traefik.io
spec:
group: traefik.io
names:
kind: Middleware
listKind: MiddlewareList
plural: middlewares
singular: middleware
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: 'Middleware is the CRD implementation of a Traefik Middleware.
More info: https://doc.traefik.io/traefik/v2.10/middlewares/http/overview/'
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: MiddlewareSpec defines the desired state of a Middleware.
properties:
addPrefix:
description: 'AddPrefix holds the add prefix middleware configuration.
This middleware updates the path of a request before forwarding
it. More info: https://doc.traefik.io/traefik/v2.10/middlewares/http/addprefix/'
properties:
prefix:
description: Prefix is the string to add before the current path
in the requested URL. It should include a leading slash (/).
type: string
type: object
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: Middleware
listKind: MiddlewareList
plural: middlewares
singular: middleware
storedVersions:
- v1alpha1
So the final question is:
How to use middlewares in Kubernetes in my case?