Skip to content

Commit 34ca470

Browse files
committed
AWS Custom-DNS: Update services that run on control plane nodes
New `update-dns-server` script that adds DNS resolvers to /etc/NetworkManager/conf.d/dns-servers.conf. The script adds the host's own IP address and the cloud metadata server's IP address to the conf file. These would then get added to the local resolv.conf by NetworkManager. This script is run as part of aws-update-dns.service This service runs when the DNSType on the AWS platform is set to "ClusterHosted".
1 parent 53e78f3 commit 34ca470

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
mode: 0755
2+
path: "/usr/local/bin/update-dns-server"
3+
contents:
4+
inline: |
5+
#!/bin/bash
6+
# For AWS, updating the NetworkManager configuration file to
7+
# include the IP address of the local node as the default DNS
8+
# resolver when UserProvisionedDNS is enabled.
9+
# A CoreDNS static pod running on the node is responsible for
10+
# resolving the api, api-int and *.apps URLs.
11+
12+
mkdir -p /etc/NetworkManager/conf.d
13+
14+
cat <<EOF | tee /etc/NetworkManager/conf.d/dns-servers.conf
15+
# Added by OpenShift
16+
[global-dns-domain-*]
17+
servers=$(ip --json route get 8.8.8.8 | jq -r ".[0].prefsrc"),169.254.169.254
18+
EOF
19+
20+
# network manager may already be running at this point.
21+
# reload to update /etc/resolv.conf with this configuration
22+
nmcli general reload conf
23+
nmcli general reload dns-rc
24+
25+
echo "Done updating dns-server.conf"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: aws-update-dns.service
2+
enabled: {{if and (eq .Infra.Status.PlatformStatus.Type "AWS") (.Infra.Status.PlatformStatus.AWS) (.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig) (eq .Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.DNSType "ClusterHosted") }}true{{else}}false{{end}}
3+
contents: |
4+
[Unit]
5+
Description=Update Default AWS Resolver
6+
# We don't need to do this on the firstboot
7+
After=firstboot-osupdate.target
8+
# Wait for NetworkManager to report it's online
9+
After=NetworkManager-wait-online.service
10+
# Run before kubelet
11+
Before=kubelet-dependencies.target
12+
13+
[Service]
14+
Type=oneshot
15+
RemainAfterExit=yes
16+
ExecStart=/usr/local/bin/update-dns-server
17+
18+
[Install]
19+
RequiredBy=kubelet-dependencies.target

0 commit comments

Comments
 (0)