<p>I am merging my applications from <code>docker</code> to <code>kubernetes</code>.</p>
<p>I am currently working with <code>minikube</code>.</p>
<p>I am using traefik as my reverse proxy, and it was installed in kubernetes using the oficial <code>helm chart</code> available at <a href="https://github.com/traefik/traefik-helm-chart" rel="nofollow noreferrer">https://github.com/traefik/traefik-helm-chart</a>.</p>
<p>Here is my working docker-compose file:</p>
<pre class="lang-yaml prettyprint-override"><code>version: &quot;3.7&quot;
services:
  myapp:
    image: nexus/my-app
    labels:
      - &quot;traefik.enable=true&quot;
      - &quot;traefik.http.routers.myapp.rule=Host(`myapp.localhost`)&quot;
      - &quot;traefik.http.routers.myapp.entrypoints=web,web-secure&quot;
      - &quot;traefik.http.routers.myapp.tls=true&quot;
      - &quot;traefik.http.routers.myapp.service=myapp&quot;
      - &quot;traefik.http.middlewares.myapp.redirectscheme.scheme=https&quot;
      - &quot;traefik.http.middlewares.myapp.redirectscheme.permanent=true&quot;
      - &quot;traefik.http.services.myapp.loadbalancer.server.port=8080&quot;
      - &quot;traefik.http.services.myapp.loadbalancer.sticky=true&quot;
      - &quot;traefik.http.services.myapp.loadbalancer.sticky.cookie.name=StickyCookieMyApp&quot;
      - &quot;traefik.http.services.myapp.loadbalancer.sticky.cookie.secure=true&quot;
      # enable the property below if your are running on https
      - &quot;traefik.http.services.myapp.loadbalancer.server.scheme=https&quot;      
    environment:
      - JAVA_OPTS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=prod
</code></pre>
<p>In Kubernetes I have the following configuration that is working:</p>
<pre class="lang-yaml prettyprint-override"><code># 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: &quot;true&quot;
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-&gt;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
</code></pre>
<p>How do I transform these three lines into Kubernetes spec?</p>
<pre class="lang-yaml prettyprint-override"><code>      - &quot;traefik.http.services.myapp.loadbalancer.sticky=true&quot;
      - &quot;traefik.http.services.myapp.loadbalancer.sticky.cookie.name=StickyCookieMyApp&quot;
      - &quot;traefik.http.services.myapp.loadbalancer.sticky.cookie.secure=true&quot;
</code></pre>

<p>You would set annotations on your service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    traefik.ingress.kubernetes.io/service.sticky.cookie: &quot;true&quot;
    traefik.ingress.kubernetes.io/service.sticky.cookie.name: cookie
    traefik.ingress.kubernetes.io/service.sticky.cookie.secure: &quot;true&quot;
[...]
</code></pre>
<p>See docs: <a href="https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/" rel="nofollow noreferrer">https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/</a></p>
