Inspired by this nice article I tried to setup a very basic Traefik environment on Kubernetes. I know this is the minimum setup without security, etc. We use Traefik for many years on Docker Swarm and want to move on to Kubernetes.
In short: this is the basic traefik yml file with deployment, service and ingressroute:
apiVersion: apps/v1
kind: Deployment
metadata:
name: traefik
spec:
selector:
matchLabels:
app: traefik
replicas: 1
template:
metadata:
labels:
app: traefik
spec:
containers:
- name: traefik
image: traefik:v2.5
ports:
- name: http
containerPort: 80
- name: admin
containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: traefik
spec:
selector:
app: traefik
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
- name: admin
port: 8080
protocol: TCP
targetPort: admin
type: NodePort
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: traefik-web-ui
spec:
entryPoints:
- web
routes:
- match: PathPrefix(`/dashboard`)
kind: Rule
services:
- name: traefik
port: 8080
The NgInx yaml is:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- name: http
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: nginx
spec:
entryPoints:
- web
routes:
- match: PathPrefix(`/nginx`)
kind: Rule
services:
- name: nginx
port: http
Applying I do with:
$ kubectl apply -f traefik.yaml
$ kubectl apply -f nginx.yaml
All is running:
Browsing to either http://localhost/dashboard, http://localhost/dashboard/, http://localhost/nginx or http://localhost/nginx/ gives no result but ERR_CONNECTION_REFUSED.
2
Answers
Thank you Fayezk13! You showed me the way to streamline my search on the internet.
Based on the 'helm install' way I found 3 ways for routing traffic via Traefik v2. I hope you can appreciate the results of hours searching on the internet.
1. Via Ingress
An example is:
2. Via IngressRoute (traefik.io/v1alpha1)
You first have to load the CRD from the Traefik site.
An example is:
3. Via traefik.containo.us/v1alpha1.
You first have to load the CRD from the Traefik site.
An example:
I would drop this method of deploying Traefik.
The official way is much more easier to deploy and manage: