---
apiVersion: apps/v1
kind: Deployment
#kind: DaemonSet
metadata:
  name: traefik
  namespace: traefik
  labels:
    k8s-app: traefik-lb
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      k8s-app: traefik-lb
  template:
    metadata:
      labels:
        k8s-app: traefik-lb
        name: traefik-pod
    spec:
      serviceAccountName: traefik
      terminationGracePeriodSeconds: 60
#     nodeSelector:
#       kubernetes.io/hostname: "dev"
      volumes:
#      - name: pv-traefik
#        persistentVolumeClaim:
#          claimName: pvc-traefik
      - name: docker-socket
        hostPath:
          path: /run/docker.sock
      containers:
      - image: traefik:2.6
        imagePullPolicy: IfNotPresent
        volumeMounts:
#        - mountPath: /config
#          name: pv-traefik
        - name: docker-socket
          mountPath: /run/docker.sock
        name: traefik-lb
        securityContext:
          runAsGroup: 998
          capabilities:
            add:
            - NET_BIND_SERVICE
            drop:
            - ALL
        ports:
        - name: ssh
          containerPort: 22
          hostPort: 22
        - name: http
          containerPort: 80
          hostPort: 80
        - name: https
          containerPort: 443
          hostPort: 443
        - name: registry
          containerPort: 5000
          hostPort: 5000
        - name: minio
          containerPort: 9000
          hostPort: 9000

        args:
        - --entrypoints.ssh.Address=:22
        - --entrypoints.web.Address=:80
        - --entrypoints.websecure.Address=:443
        - --entrypoints.registry.Address=:5000
        - --entrypoints.minio.Address=:9000

        - --entrypoints.web.http.redirections.entryPoint.to=websecure
        - --entrypoints.web.http.redirections.entryPoint.scheme=https
        - --entrypoints.web.http.redirections.entrypoint.priority=1

        - --api.dashboard=true
        - --pilot.dashboard=false

        - --log=true
        - --log.level=INFO
        - --log.format=json
        - --log.filePath=/dev/stdout
        - --accesslog=false
        - --accesslog.format=common # json
        - --accesslog.filepath=/dev/stdout

        - --serverstransport.insecureskipverify=true
        - --providers.docker=true
        - --providers.docker.endpoint=unix:///run/docker.sock
        - --providers.docker.exposedbydefault=false
        - --providers.docker.defaultRule=Host(`{{ normalize .Name }}.apps.gamehost.fi`)
        - --providers.kubernetescrd=true
        - --providers.kubernetescrd.allowCrossNamespace=true
        - --providers.kubernetesingress=true
        - --providers.kubernetesingress.allowemptyservices=true
        - --providers.file.filename=/config/traefik.yaml
#       - --providers.file.directory=/config/
        - --providers.file.watch=true
