Migrate AdGuard deployment+service to Argo CD apps/
This commit is contained in:
+2
-146
@@ -42,151 +42,7 @@ resource "kubernetes_persistent_volume_claim" "adguard_data" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "kubernetes_deployment" "adguard" {
|
# Deployment + Service managed by Argo CD — see servers/legion/apps/adguard.yaml
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "kubernetes_ingress_v1" "adguard" {
|
resource "kubernetes_ingress_v1" "adguard" {
|
||||||
metadata {
|
metadata {
|
||||||
@@ -212,7 +68,7 @@ resource "kubernetes_ingress_v1" "adguard" {
|
|||||||
path_type = "Prefix"
|
path_type = "Prefix"
|
||||||
backend {
|
backend {
|
||||||
service {
|
service {
|
||||||
name = kubernetes_service.adguard_ui.metadata[0].name
|
name = "adguard-ui"
|
||||||
port {
|
port {
|
||||||
number = 3000
|
number = 3000
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user