Hello all.
I'm moving our containeres from SWARM to K8S, simple as that. In our swarm we use Traefik 1.7 as reverse proxy and in our K8S we are using Traefik 2.4, everything new must be fresh right? =D
But now, I have a problem, and all the searchs I've made so far don't give me a clue on how to put it to work.
On my swarm I have this docker-compose:
version: '3.4'
services:
latest:
image: mysql:latest
volumes:
- /mypath/mysql/db:/var/lib/mysql
- /mypath/mysql/dump:/dump
environment:
- MYSQL_ROOT_PASSWORD=itsasecret
ports:
- 3306:3306
deploy:
labels:
- traefik.backend=mysql
- traefik.frontend.rule=Host:myurl
placement:
constraints:
- node.labels.so==linux
networks:
- traefik
networks:
- traefik
networks:
traefik:
external: true
And it works like a charm..... simple connect with MySQL Workbench and be happy.
But now there is K8S....
Thats my deploy of Traefik:
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: traefik-daemon-set
labels:
applicationn: traefik-daemon-set
spec:
selector:
matchLabels:
app: traefik
template:
metadata:
labels:
applicationn: traefik-daemon-set
spec:
serviceAccountName: traefik-ingress-controller
terminationGracePeriodSeconds: 60
containers:
- image: traefik:v2.4
name: traefik-ingress-lb
ports:
- name: http
containerPort: 80
hostPort: 80
- name: https
containerPort: 443
hostPort: 443
- name: admin
containerPort: 8080
hostPort: 8080
- name: mysql
hostPort: 3306
containerPort: 3306
protocol: TCP
securityContext:
capabilities:
drop:
- ALL
add:
- NET_BIND_SERVICE
args:
- --api.insecure
- --api.dashboard
# Specify that we want to use Traefik as an Ingress Controller.
- --providers.kubernetesingress
# Define two entrypoint ports, and setup a redirect from HTTP to HTTPS.
- --entryPoints.web.address=:80
- --entryPoints.websecure.address=:443
#- --entrypoints.web.http.redirections.entryPoint.to=websecure
#- --entrypoints.web.http.redirections.entryPoint.scheme=https
- --entryPoints.mysql.address=:3306
- --log.level=INFO
- --accesslog=true
- --log=true
- --metrics=true
And there is my custom resources created for Traefik:
# All resources definition must be declared
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingressroutes.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: IngressRoute
plural: ingressroutes
singular: ingressroute
scope: Namespaced
---
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
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingressroutetcps.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: IngressRouteTCP
plural: ingressroutetcps
singular: ingressroutetcp
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingressrouteudps.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: IngressRouteUDP
plural: ingressrouteudps
singular: ingressrouteudp
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: tlsoptions.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: TLSOption
plural: tlsoptions
singular: tlsoption
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: tlsstores.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: TLSStore
plural: tlsstores
singular: tlsstore
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: traefikservices.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: TraefikService
plural: traefikservices
singular: traefikservice
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: serverstransports.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: ServersTransport
plural: serverstransports
singular: serverstransport
scope: Namespaced
And, finally, my MySQL deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-latest
namespace: company-prod
spec:
replicas: 1
selector:
matchLabels:
app: mysql-latest
template:
metadata:
labels:
app: mysql-latest
spec:
containers:
- name: mysql-latest
image: mysql:latest
env:
- name: "MYSQL_ROOT_PASSWORD"
value: "itsasecret"
ports:
- containerPort: 3306
volumeMounts:
- name: mysql
mountPath: "/var/lib/mysql"
- name: dump
mountPath: "/dump"
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: 1000m
memory: 1024Mi
volumes:
- name: mysql
hostPath:
path: "/mysqltestmigration/db"
- name: dump
hostPath:
path: "/mysqltestmigration/dump"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-latest
namespace: company-prod
spec:
selector:
app: mysql-latest
ports:
- protocol: TCP
port: 3306
targetPort: 3306
type: ClusterIP
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: mysql-latest
namespace: company-prod
spec:
entryPoints:
- mysql
routes:
- match: HostSNI(`myurl`)
services:
- name: mysql-latest
port: mysql
In my Traefik, I can see the entrypoint creation:
But not in TCP:
Can anyone tell me where I'm doing something wrong? Thx