apiVersion: apps/v1
kind: Deployment
metadata:
  name: pihole
  labels:
    app: pihole
spec:
  strategy:
    type: Recreate
  replicas: 1
  selector:
    matchLabels:
      app: pihole
  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/path: /metrics
        prometheus.io/port: '8081'
      labels:
        app: pihole
        name: pihole
    spec:
      containers:
      - name: pihole
        image: registry.homelab.dsb.dev/pihole/pihole:v5.8.1
        imagePullPolicy: IfNotPresent
        env:
        - name: TZ
          value: Europe/London
        - name: WEBPASSWORD
          valueFrom:
            secretKeyRef:
              name: pihole
              key: pihole.password
        # Point DNS to cloudflared for DNS over HTTPS.
        - name: DNS1
          value: 127.0.0.1#5053
        - name: DNS2
          value: ''
        volumeMounts:
        - name: pihole
          mountPath: /etc/pihole
          subPath: pihole
        - name: pihole
          mountPath: /etc/dnsmasq.d
          subPath: dnsmasq
        readinessProbe:
          tcpSocket:
            port: 80
      - name: cloudflared
        image: registry.homelab.dsb.dev/raspbernetes/cloudflared:2021.7.0
        env:
        - name: TUNNEL_DNS_ADDRESS
          value: 0.0.0.0
        - name: TUNNEL_DNS_PORT
          value: "5053"
        - name: TUNNEL_DNS_UPSTREAM
          value: https://1.1.1.1/dns-query,https://1.0.0.1/dns-query
        - name: TUNNEL_METRICS
          value: 0.0.0.0:8081
        command:
          - cloudflared
        args:
          - --no-autoupdate
          - proxy-dns
      volumes:
      - name: pihole
        persistentVolumeClaim:
          claimName: pihole
