Migrate AdGuard deployment+service to Argo CD apps/

This commit is contained in:
Will Anderson
2026-03-23 08:05:18 -05:00
parent 5231adc3a0
commit b2b04c231c
2 changed files with 93 additions and 146 deletions
+2 -146
View File
@@ -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
}
+91
View File
@@ -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