我的 AGH pod 遇到问题,每次容器关闭时都必须重新配置;无论是手动还是在服务器重新启动时。
这些是各种 YAML:
---
apiVersion: v1
kind: Namespace
metadata:
name: adguard
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: adguard-data-pv
namespace: adguard
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/tank/apps/adguard/data"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: adguard-conf-pv
namespace: adguard
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/tank/apps/adguard/conf"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: adguard-data-pvc
namespace: adguard
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeName: adguard-data-pv
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: adguard-conf-pvc
namespace: adguard
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeName: adguard-conf-pv
---
apiVersion: v1
kind: ConfigMap
metadata:
name: adguard-config
namespace: adguard
data:
AdGuardHome.yaml: |
bind_host: 0.0.0.0
bind_port: 3000
auth_name: "admin"
auth_pass: "[REDACTED]"
language: "en"
rlimit_nofile: 0
rlimit_nproc: 0
log_file: ""
log_syslog: false
log_syslog_srv: ""
pid_file: ""
verbose: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: adguard-deployment
namespace: adguard
spec:
replicas: 1
selector:
matchLabels:
app: adguard
template:
metadata:
labels:
app: adguard
spec:
containers:
- name: adguard-home
image: adguard/adguardhome:latest
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "1000m"
env:
- name: AGH_CONFIG
valueFrom:
configMapKeyRef:
name: adguard-config
key: AdGuardHome.yaml
ports:
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 53
name: dns-udp
protocol: UDP
- containerPort: 67
name: dhcp-one
protocol: UDP
- containerPort: 68
name: dhcp-two
protocol: TCP
- containerPort: 68
name: dhcp-three
protocol: UDP
- containerPort: 80
name: http-tcp
protocol: TCP
- containerPort: 443
name: doh-tcp
protocol: TCP
- containerPort: 443
name: doh-udp
protocol: UDP
- containerPort: 3000
name: http-initial
- containerPort: 784
name: doq-one
protocol: UDP
- containerPort: 853
name: dot
protocol: TCP
- containerPort: 853
name: doq-two
protocol: UDP
- containerPort: 5443
name: dnscrypt-tcp
protocol: TCP
- containerPort: 5443
name: dnscrypt-udp
protocol: UDP
volumeMounts:
- name: adguard-data
mountPath: /opt/adguardhome/work
- name: adguard-conf
mountPath: /opt/adguardhome/conf
volumes:
- name: adguard-data
persistentVolumeClaim:
claimName: adguard-data-pvc
- name: adguard-conf
persistentVolumeClaim:
claimName: adguard-conf-pvc
---
apiVersion: v1
kind: Service
metadata:
name: adguard-service
namespace: adguard
spec:
selector:
app: adguard
ports:
- protocol: TCP
port: 3000
targetPort: 3000
name: http-initial
- protocol: TCP
port: 80
targetPort: 80
name: http-tcp
- protocol: UDP
port: 53
targetPort: 53
name: dns-udp
- protocol: TCP
port: 53
targetPort: 53
name: dns-tcp
- protocol: UDP
port: 67
targetPort: 67
name: dhcp-one
- protocol: TCP
port: 68
targetPort: 68
name: dhcp-two
- protocol: UDP
port: 68
targetPort: 68
name: dhcp-three
- protocol: TCP
port: 443
targetPort: 443
name: doh-tcp
- protocol: UDP
port: 443
targetPort: 443
name: doh-udp
- protocol: UDP
port: 784
targetPort: 784
name: doq-one
- protocol: TCP
port: 853
targetPort: 853
name: dot
- protocol: UDP
port: 853
targetPort: 853
name: doq-two
- protocol: TCP
port: 5443
targetPort: 5443
name: dnscrypt-tcp
- protocol: UDP
port: 5443
targetPort: 5443
name: dnscrypt-udp
type: LoadBalancer
externalTrafficPolicy: Local
我必须承认我是 Kubernetes 的新手,所以也许我做错了什么?然而,我确实感到困惑的是,以类似的方式部署 Plex 似乎效果很好;我可以停止、销毁等并重新部署它,然后它就开始了,就好像什么都没发生过一样。
我在 ZFS 上使用
microk8s
和 metallb
(用于数据)。
我发现了问题所在:首次应用各种 YAML 启动 pod/堆栈 - 这会使用
AdGuardHome.yaml
中的模板/参数创建一个 adguard-config.yml
文件。使用 Web UI 应用更改并连续执行 cat /path/to/AdGuardHome.yaml
,您可以看到文件的内容发生更改(即 Web UI 中的更改写入该文件)。我发现 ConfigMap
在 k8s
中通常是不可变的,除非您设置自动重新加载机制,这基本上意味着每次重新启动系统、销毁/重新部署 pod 时,都会应用原始的 ConfigMap
.
目前,我的解决方法就是在
adguard-deployment.yml
中注释掉以下内容:
...
#env:
# - name: AGH_CONFIG
# valueFrom:
# configMapKeyRef:
# name: adguard-config
# key: AdGuardHome.yaml
...
并做一个
# microk8s kubectl apply -f adguard-deployment.yml
。
我知道这可能不是最佳/正确的方法,但它目前有效;至少在我更好地理解
k8s
之前。
作为一个小附录:我认为一个可行的解决方法是添加一个
initContainer
来检查文件是否已存在于给定路径中;如果没有,请应用 adguard-config.yml
的内容创建它。