apiVersion: apps/v1
kind: Deployment
metadata:
  name: adguard-deploy
  labels:
    app.kubernetes.io/name: adguard-deploy
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: adguard-app
  template:
    metadata:
      labels:
        app.kubernetes.io/name: adguard-app
    spec:
      serviceAccountName: default
      dnsPolicy: ClusterFirst
      enableServiceLinks: true
      initContainers:
        - command:
          - sh
          - -c
          - |
            if [ ! -f /opt/adguardhome/conf/AdGuardHome.yaml ]; then
              mkdir -p /opt/adguardhome/conf
              cp /tmp/AdGuardHome.yaml /opt/adguardhome/conf/AdGuardHome.yaml
            fi
          image: busybox
          name: copy-configmap
          securityContext:
            runAsUser: 0
          volumeMounts:
          - mountPath: /tmp/AdGuardHome.yaml
            name: adguard-config
            subPath: AdGuardHome.yaml
          - mountPath: /opt/adguardhome/conf
            name: config
      containers:
      - name: adguard-adguard
        image: "adguard/adguardhome:v0.105.2"
        imagePullPolicy: IfNotPresent
        args:
        - --config
        - /opt/adguardhome/conf/AdGuardHome.yaml
        - --no-check-update
        ports:
        - name: http
          containerPort: 3000
          protocol: TCP
        volumeMounts:
        - mountPath: /opt/adguardhome/conf
          name: config
        - mountPath: /tmp/AdGuardHome.yaml
          name: adguard-config
          subPath: AdGuardHome.yaml
        
        livenessProbe:
          tcpSocket:
            port: http
          initialDelaySeconds: 0
          failureThreshold: 3
          timeoutSeconds: 1
          periodSeconds: 10
        readinessProbe:
          tcpSocket:
            port: http
          initialDelaySeconds: 0
          failureThreshold: 3
          timeoutSeconds: 1
          periodSeconds: 10
        startupProbe:
          tcpSocket:
            port: http
          initialDelaySeconds: 0
          failureThreshold: 30
          timeoutSeconds: 1
          periodSeconds: 5
      volumes:
      - name: config
        emptyDir: {}
      - configMap:
          name: adguard-config
        name: adguard-config
