I am merging my applications from docker
to kubernetes
.
I am currently working with minikube
.
I am using traefik as my reverse proxy, and it was installed in kubernetes using the oficial helm chart
available at https://github.com/traefik/traefik-helm-chart.
Here is my working docker-compose file:
version: "3.7"
services:
myapp:
image: nexus/my-app
labels:
- "traefik.enable=true"
- "traefik.http.routers.myapp.rule=Host(`myapp.localhost`)"
- "traefik.http.routers.myapp.entrypoints=web,web-secure"
- "traefik.http.routers.myapp.tls=true"
- "traefik.http.routers.myapp.service=myapp"
- "traefik.http.middlewares.myapp.redirectscheme.scheme=https"
- "traefik.http.middlewares.myapp.redirectscheme.permanent=true"
- "traefik.http.services.myapp.loadbalancer.server.port=8080"
- "traefik.http.services.myapp.loadbalancer.sticky=true"
- "traefik.http.services.myapp.loadbalancer.sticky.cookie.name=StickyCookieMyApp"
- "traefik.http.services.myapp.loadbalancer.sticky.cookie.secure=true"
# enable the property below if your are running on https
- "traefik.http.services.myapp.loadbalancer.server.scheme=https"
environment:
- JAVA_OPTS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=prod
In Kubernetes I have the following configuration that is working:
# HTTPS ingress
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: myapp-ingress
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
spec:
rules:
- host: myapp.localhost
http:
paths:
- backend:
serviceName: myapp
servicePort: 8080
tls:
- secretName: myapp-cert
---
# Ingresses
# this middleware is used as the following annotation:
# traefik.ingress.kubernetes.io/router.middlewares: default-redirect@kubernetescrd
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: redirect
spec:
redirectScheme:
scheme: https
permanent: true
---
# http ingress for http->https redirection
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: myapp-redirect
annotations:
traefik.ingress.kubernetes.io/router.middlewares: default-redirect@kubernetescrd
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: myapp.localhost
http:
paths:
- backend:
serviceName: myapp
servicePort: 8080
How do I transform these three lines into Kubernetes spec?
- "traefik.http.services.myapp.loadbalancer.sticky=true"
- "traefik.http.services.myapp.loadbalancer.sticky.cookie.name=StickyCookieMyApp"
- "traefik.http.services.myapp.loadbalancer.sticky.cookie.secure=true"