我尝试构建一个运行需要的服务的 Pod:
- 由其 FQDN (
*.cluster.local
) 解析和访问的集群内部服务, - 同时还具有与远程集群的活动 OpenVPN 连接,并且来自该远程集群的服务将由其 FQDN (
*.cluster.remote
) 解析和访问。
Pod 中没有 OpenVPN sidecar 的服务容器可以访问所有使用*.cluster.local
命名空间提供 FQDN 的服务。这是/etc/resolv.conf
在这种情况下:
nameserver 169.254.25.10
search default.cluster.local svc.cluster.local cluster.local
options ndots:5
当 OpenVPN sidecar 管理时resolv.conf
OpenVPN sidecar 的启动方式如下:
containers:
{{- if .Values.vpn.enabled }}
- name: vpn
image: "ghcr.io/wfg/openvpn-client"
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
volumeMounts:
- name: vpn-working-directory
mountPath: /data/vpn
env:
- name: KILL_SWITCH
value: "off"
- name: VPN_CONFIG_FILE
value: connection.conf
securityContext:
privileged: true
capabilities:
add:
- "NET_ADMIN"
resources:
limits:
cpu: 100m
memory: 80Mi
requests:
cpu: 25m
memory: 20Mi
{{- end }}
OpenVPN 客户端配置包含以下几行:
script-security 2
up /etc/openvpn/up.sh
down /etc/openvpn/down.sh
然后 OpenVPN 客户端将覆盖resolv.conf
,使其包含以下内容:
nameserver 192.168.255.1
options ndots:5
在这种情况下,*.cluster.remote
解析中的任何服务,但没有来自 的服务*.cluster.local
。这是意料之中的。
当 OpenVPN sidecar 不管理resolv.conf
,但spec.dnsConfig
提供时
从 OpenVPN 客户端配置中删除以下行:
script-security 2
up /etc/openvpn/up.sh
down /etc/openvpn/down.sh
提供spec.dnsConfig
如下:
dnsConfig:
nameservers:
- 192.168.255.1
searches:
- cluster.remote
然后,resolv.conf
将是以下内容:
nameserver 192.168.255.1
nameserver 169.254.25.10
search default.cluster.local svc.cluster.local cluster.local cluster.remote
options ndots:5
这适用于*.cluster.remote
,但不适用于任何东西*.cluster.local
,因为只要第一个超时,就会尝试第二个名称服务器。我注意到有些人会通过设置命名空间轮换和超时 1 秒来绕过这个限制,但是这种行为对我来说看起来很忙,我不会考虑这个,甚至不是一种解决方法。或者,也许我错过了一些东西。我的第一个问题是:在这种情况下轮换和超时可以工作吗?
我的第二个问题是:有什么方法可以使*.cluster.local
和*.cluster.remote
DNS 解析从 Pod 内的服务容器可靠地工作,而无需使用类似的东西dnsmasq
?
我的第三个问题是:如果dnsmasq
需要,我如何配置、提供和覆盖它,resolv.conf
同时确保 Kubernetes 提供的名称服务器可以是任何东西(169.254.25.10
在这种情况下)。
最好的,佐尔坦