Hey everyone...
I've got some problems using Traefik 2.4 running on kubernetes (bare metal).
I want to have a service behind the path /flask but the backend service should get /.
Here's how I have done the config ( sorry for all the files but i tried a lot of things and feel like someone who really understands it will find the error prett quickly )
Clusterrole + Middleware
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
rules:
- apiGroups:
- ""
resources:
- services
- endpoints
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- extensions
- networking.k8s.io
resources:
- ingresses
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- ingresses/status
verbs:
- update
# i feel like these are the own ressources below
- apiGroups:
- traefik.containo.us
resources:
- middlewares
- ingressroutes
- traefikservices
- ingressroutetcps
- ingressrouteudps
- tlsoptions
- tlsstores
- serverstransports
verbs:
- get
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
name: traefik-ingress-controller
namespace: kube-system
---
# added later
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: middlewares.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: Middleware
plural: middlewares
singular: middleware
scope: Namespaced
Ingress + Middleware
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: stripprefix
spec:
replacePath:
prefixes:
- /blue
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
namespace: default
annotations:
#traefik.ingress.kubernetes.io/rewrite-target: /$2
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: default-stripprefix #also tried @kubernetescrd
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: flask-docker-service
port:
number: 80
- path: /blue
pathType: Prefix
backend:
service:
name: flask-docker-service
port:
number: 80
Daemonset + Service Account
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik-ingress-controller
namespace: kube-system
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
namespace: kube-system
name: traefik
labels:
app: traefik
spec:
selector:
matchLabels:
app: traefik
template:
metadata:
labels:
app: traefik
spec:
serviceAccountName: traefik-ingress-controller
containers:
- name: traefik
image: traefik:v2.4
args:
- --api
- --api.insecure
- --accesslog
- --log.level=DEBUG
- --entrypoints.web.Address=:80
- --entrypoints.websecure.Address=:443
- --providers.kubernetesingress=true
ports:
- name: web
containerPort: 80
hostPort: 80
- name: websecure
containerPort: 443
hostPort: 443
Service:
kind: Service
apiVersion: v1
metadata:
name: traefik
namespace: kube-system
spec:
ports:
- protocol: TCP
name: web
port: 80
- protocol: TCP
name: admin
port: 8080
- protocol: TCP
name: websecure
port: 443
selector:
app: traefik
Right now in the logs of the traffic pod it says:
level=error msg="middleware "default-stripprefix@kubernetes" does not exist" routerName=minimal-ingress-default@kubernetes entryPointName=websecure
Also tried different things e.g. default-stripprefix ... and also different cli parameters in Daemonset but can't figure it out.
Thanks in advance for your help