apiVersion: v1
kind: Service
metadata:
  name: companion
  namespace: companion
  labels:
    app: companion
spec:
  ports:
    - port: 80
      targetPort: 3020
      protocol: TCP
  selector:
    app: companion
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: companion
  namespace: companion
spec:
  selector:
    matchLabels:
      app: companion
  replicas: 2
  updateStrategy:
    type: RollingUpdate
  serviceName: 'companion'
  template:
    metadata:
      labels:
        app: companion
    spec:
      containers:
        - image: docker.io/transloadit/companion:latest
          imagePullPolicy: Always
          name: companion
          envFrom:
            - secretRef:
                name: companion-env
          ports:
            - containerPort: 3020
          volumeMounts:
            - name: companion-data
              mountPath: /mnt/companion-data
  volumeClaimTemplates:
    - metadata:
        name: companion-data
      spec:
        accessModes: ['ReadWriteOnce']
        resources:
          requests:
            storage: 10Gi
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: companion
  namespace: companion
  annotations:
    kubernetes.io/tls-acme: 'true'
    kubernetes.io/ingress.class: 'nginx'
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    certmanager.k8s.io/acme-http01-edit-in-place: 'true'
spec:
  tls:
    - secretName: server-tls
      hosts:
        - companion.uppy.io
    - secretName: uppy-tls
      hosts:
        - server.uppy.io
  rules:
    - host: companion.uppy.io
      http:
        paths:
          - path: /
            backend:
              serviceName: companion
              servicePort: 80
    - host: server.uppy.io
      http:
        paths:
          - path: /
            backend:
              serviceName: companion
              servicePort: 80
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: companion
  namespace: companion
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Statefulset
    name: companion
  minReplicas: 1
  maxReplicas: 5
  targetCPUUtilizationPercentage: 80
