apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: traefik-ingress-controller-external
  namespace: kube-system
  labels:
    k8s-app: traefik-ingress-lb-external
spec:
  serviceName: traefik-ingress-lb-external
  replicas: 2
  selector:
    matchLabels:
      k8s-app: traefik-ingress-lb-external
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb-external
        name: traefik-ingress-lb-external
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
      # Remove the initContainer in case of a *big operation* to avoid inconsistencies when
      # starting multiple pods in parallel. Might be a case a pod starts with partial config
      # because another pod is overwriting the config in KV.
      #initContainers:
      #- name: storeconfig
      #  image: traefik:v1.6
      #  imagePullPolicy: IfNotPresent
      #  args:
      #  - storeconfig
      #  - -c
      #  - /config/traefik.toml
      #  volumeMounts:
      #  - name: config
      #    mountPath: /etc/traefik
      #    readOnly: true
      containers:
      - image: traefik:v1.7
        name: traefik-ingress-lb
        ports:
         - name: http
           containerPort: 80
         - name: https
           containerPort: 443
         - name: admin
           containerPort: 8080
        args:
        - --api
        - --configfile=/config/traefik.toml
        env:
          - name: GODADDY_API_KEY
            valueFrom:
              secretKeyRef:
                key: key
                name: traefik-external-godaddy
          - name: GODADDY_API_SECRET
            valueFrom:
              secretKeyRef:
                key: secret
                name: traefik-external-godaddy
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 180
          periodSeconds: 3
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 100m
            memory: 64Mi
          limits:
            cpu: 200m
            memory: 256Mi
        volumeMounts:
        - mountPath: /config
          name: config
      volumes:
      - name: config
        configMap:
          name: traefik-conf-external
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: k8s-app
                  operator: In
                  values:
                  - traefik-ingress-lb
              topologyKey: kubernetes.io/hostname
