apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: home-apps
  name: adguard-nfs-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: nfs-client
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: adguard
  namespace: home-apps
  labels:
    app: adguard
spec:
  revisionHistoryLimit: 3
  replicas: 1
  selector:
    matchLabels:
      app: adguard
  template:
    metadata:
      labels:
        app: adguard
        name: adguard
    spec:
      # nodeSelector:
      #    gateway: "true"
      # tolerations:
      #   - effect: NoSchedule
      #     operator: Exists
      imagePullSecrets:
        - name: regcred
      containers:
        - name: adguard
          image: mirror.gcr.io/adguard/adguardhome:v0.108.0-b.33
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              name: adguard-http
              protocol: TCP
            - containerPort: 3000
              name: adguard-http2
              protocol: TCP
            - containerPort: 53
              name: dns
              protocol: TCP
            - containerPort: 53
              name: dns-udp
              protocol: UDP
            - containerPort: 443
              name: adguard-ssl
              protocol: TCP
            - containerPort: 67
              name: client-udp
              protocol: UDP
            - containerPort: 68
              name: dhcp
              protocol: TCP
            - containerPort: 68
              name: dhcp-udp
              protocol: UDP
            - containerPort: 853
              name: dns-over-tls
              protocol: TCP
            - containerPort: 784
              name: dns-over-quic2
              protocol: UDP
            - containerPort: 853
              name: dns-over-quic
              protocol: UDP
            - containerPort: 5443
              name: dnscrypt-tcp
              protocol: TCP
            - containerPort: 5443
              name: dnscrypt-udp
              protocol: UDP
          env:
            - name: TZ
              value: "Australia/Melbourne"
          volumeMounts:
            - name: configs
              subPath: conf
              mountPath: "/opt/adguardhome/conf"
            - name: configs
              subPath: work
              mountPath: "/opt/adguardhome/work"
          resources:
            requests:
              cpu: 300m
              memory: 512Mi
            limits:
              cpu: 600m
              memory: 1Gi
      volumes:
        - name: configs
          persistentVolumeClaim:
            claimName: adguard-nfs-pvc

---

apiVersion: v1
kind: Service
metadata:
  name: adguard-metallb
  namespace: home-apps
  annotations:
    metallb.universe.tf/loadBalancerIPs: 192.168.1.200
  labels:
    name: adguard-dns
spec:
  type: LoadBalancer
  externalIPs:
    - 192.168.1.200
  selector:
    app: adguard
  ports:
  - name: adguard-http
    port: 80
    protocol: TCP
  - name: dns
    port: 53
    protocol: UDP
  - name: dnstcp
    port: 53
    protocol: TCP
  - port: 67
    name: client-udp
    protocol: UDP
  - port: 68
    name: dhcp
    protocol: TCP
  - port: 68
    name: dhcp-udp
    protocol: UDP
  - port: 853
    name: dns-over-tls
    protocol: TCP
  - port: 784
    name: dns-over-quic2
    protocol: UDP
  - port: 853
    name: dns-over-quic
    protocol: UDP
  - port: 5443
    name: dnscrypt-tcp
    protocol: TCP
  - port: 5443
    name: dnscrypt-udp
    protocol: UDP
  - port: 3000
    name: adguard-http2
    protocol: TCP

---

apiVersion: v1
kind: Service
metadata:
  name: adguard-web
  namespace: home-apps
  labels:
    name: adguard-web
spec:
  type: ClusterIP
  selector:
    app: adguard
  ports:
    - name: adguard
      targetPort: adguard-http
      port: 80
      protocol: TCP

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: adguard-ingress
  namespace: home-apps
  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://pass.junv.cc/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://pass.junv.cc/oauth2/start?rd=https://$host$escaped_request_uri"
spec:
  tls:
  - hosts:
    - adguard.junv.cc
    secretName: adguard-tls
  rules:
  - host: adguard.junv.cc
    http:
      paths:
      - backend:
          service:
            name: adguard-web
            port:
              number: 80
        path: /
        pathType: Prefix
