apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarr
spec:
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: sonarr
  replicas: 1
  template:
    metadata:
      labels:
        app: sonarr
    spec:
      volumes:
        - name: config
          persistentVolumeClaim:
            claimName: configs-nfs
        - name: downloads
          persistentVolumeClaim:
            claimName: downloads-nfs
      imagePullSecrets:
        - name: regcred
      containers:
        - name: sonarr
          image: linuxserver/sonarr
          securityContext:
            runAsUser: 0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8989
              name: sonarr-port
              protocol: TCP
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: TZ
              value: Australia/Melbourne
          volumeMounts:
            - name: config
              subPath: sonarr
              mountPath: /config
            - name: downloads
              subPath: sonarr
              mountPath: /tv
            - name: downloads
              subPath: sonarr
              mountPath: /downloads
          resources:
            requests:
              cpu: 200m
              memory: 512Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: sonarr
  labels:
    app: sonarr
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: sonarr-port
      protocol: TCP
  selector:
    app: sonarr

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sonarr-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://id.junv.cc/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://id.junv.cc/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
  tls:
  - hosts:
    - sonarr.junv.cc
    secretName: sonarr-tls
  rules:
  - host: sonarr.junv.cc
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: sonarr
            port:
              number: 80

---
