From b2b04c231c602e7c8f7513f011f1c30b328641e7 Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Mon, 23 Mar 2026 08:05:18 -0500 Subject: [PATCH] Migrate AdGuard deployment+service to Argo CD apps/ --- servers/legion/adguard.tf | 148 +------------------------------ servers/legion/apps/adguard.yaml | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+), 146 deletions(-) create mode 100644 servers/legion/apps/adguard.yaml diff --git a/servers/legion/adguard.tf b/servers/legion/adguard.tf index e288219..5dfd241 100644 --- a/servers/legion/adguard.tf +++ b/servers/legion/adguard.tf @@ -42,151 +42,7 @@ resource "kubernetes_persistent_volume_claim" "adguard_data" { } } -resource "kubernetes_deployment" "adguard" { - metadata { - name = "adguard" - namespace = kubernetes_namespace.dns.metadata[0].name - labels = { - app = "adguard" - } - } - - spec { - replicas = 1 - - strategy { - type = "Recreate" - } - - selector { - match_labels = { - app = "adguard" - } - } - - template { - metadata { - labels = { - app = "adguard" - } - } - - spec { - # hostNetwork gives AdGuard direct access to port 53 on the host IP - host_network = true - dns_policy = "ClusterFirstWithHostNet" - - # Ensure bind_hosts is always 0.0.0.0 regardless of what was written to the PVC - init_container { - name = "fix-bind-hosts" - image = "python:3.12-alpine" - command = ["python3", "-c"] - args = [<<-EOT - import re, os - config = "/opt/adguardhome/conf/AdGuardHome.yaml" - if os.path.exists(config): - with open(config) as f: - content = f.read() - # Replace any bind_hosts list with 0.0.0.0 - content = re.sub( - r'(bind_hosts:\n)((?:[ \t]*- .*\n)*)', - 'bind_hosts:\n - 0.0.0.0\n', - content - ) - with open(config, "w") as f: - f.write(content) - print("bind_hosts set to 0.0.0.0") - else: - print("No config yet — AdGuard will create it on first run") - EOT - ] - volume_mount { - name = "config" - mount_path = "/opt/adguardhome/conf" - } - } - - container { - name = "adguard" - image = "adguard/adguardhome:latest" - - port { - name = "dns-tcp" - container_port = 53 - protocol = "TCP" - } - port { - name = "dns-udp" - container_port = 53 - protocol = "UDP" - } - port { - name = "http" - container_port = 3000 - protocol = "TCP" - } - - volume_mount { - name = "config" - mount_path = "/opt/adguardhome/conf" - } - - volume_mount { - name = "data" - mount_path = "/opt/adguardhome/work" - } - - resources { - requests = { - memory = "128Mi" - cpu = "100m" - } - limits = { - memory = "512Mi" - cpu = "500m" - } - } - } - - volume { - name = "config" - persistent_volume_claim { - claim_name = kubernetes_persistent_volume_claim.adguard_config.metadata[0].name - } - } - - volume { - name = "data" - persistent_volume_claim { - claim_name = kubernetes_persistent_volume_claim.adguard_data.metadata[0].name - } - } - } - } - } -} - -# UI accessible via Traefik ingress (port 3000 → ingress) -resource "kubernetes_service" "adguard_ui" { - metadata { - name = "adguard-ui" - namespace = kubernetes_namespace.dns.metadata[0].name - } - - spec { - selector = { - app = "adguard" - } - - port { - name = "http" - port = 3000 - target_port = 3000 - } - - type = "ClusterIP" - } -} +# Deployment + Service managed by Argo CD — see servers/legion/apps/adguard.yaml resource "kubernetes_ingress_v1" "adguard" { metadata { @@ -212,7 +68,7 @@ resource "kubernetes_ingress_v1" "adguard" { path_type = "Prefix" backend { service { - name = kubernetes_service.adguard_ui.metadata[0].name + name = "adguard-ui" port { number = 3000 } diff --git a/servers/legion/apps/adguard.yaml b/servers/legion/apps/adguard.yaml new file mode 100644 index 0000000..3c5bdf6 --- /dev/null +++ b/servers/legion/apps/adguard.yaml @@ -0,0 +1,91 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: adguard + namespace: dns + labels: + app: adguard +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: adguard + template: + metadata: + labels: + app: adguard + spec: + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + initContainers: + - name: fix-bind-hosts + image: python:3.12-alpine + command: ["python3", "-c"] + args: + - | + import re, os + config = "/opt/adguardhome/conf/AdGuardHome.yaml" + if os.path.exists(config): + with open(config) as f: + content = f.read() + content = re.sub( + r'(bind_hosts:\n)((?:[ \t]*- .*\n)*)', + 'bind_hosts:\n - 0.0.0.0\n', + content + ) + with open(config, "w") as f: + f.write(content) + print("bind_hosts set to 0.0.0.0") + else: + print("No config yet — AdGuard will create it on first run") + volumeMounts: + - name: config + mountPath: /opt/adguardhome/conf + containers: + - name: adguard + image: adguard/adguardhome:latest + ports: + - name: dns-tcp + containerPort: 53 + protocol: TCP + - name: dns-udp + containerPort: 53 + protocol: UDP + - name: http + containerPort: 3000 + protocol: TCP + volumeMounts: + - name: config + mountPath: /opt/adguardhome/conf + - name: data + mountPath: /opt/adguardhome/work + resources: + requests: + memory: 128Mi + cpu: 100m + limits: + memory: 512Mi + cpu: 500m + volumes: + - name: config + persistentVolumeClaim: + claimName: adguard-config + - name: data + persistentVolumeClaim: + claimName: adguard-data +--- +apiVersion: v1 +kind: Service +metadata: + name: adguard-ui + namespace: dns +spec: + selector: + app: adguard + ports: + - name: http + port: 3000 + targetPort: 3000 + type: ClusterIP