GeekCoding101 make your way to geek

K8s Tutorial Part 2: BIND DNS and Chrony NTP on Rocky 9

Kubernetes on Mac, Part 2: clone a Rocky Linux 9 VM into a BIND DNS server with forward and reverse zones, plus a Chrony NTP server.

10 min read
Kubernetes Tutorials Feature Image Setup Cluster Part2 1
On this pageWhat we’re building

In this part we clone the Rocky Linux 9 base image from Part 1 into a new VM called localserver and turn it into the lab’s DNS server (BIND) and NTP server (Chrony). When we’re done, every node in the cluster can reach the others by hostname instead of IP, and they all take their time from one local source. 🚀

I thought about squeezing the Kubernetes master and worker setup into this post too, but it got way too long. The real cluster comes in Part 3. 😎

What we’re building

HostIPRole
localserver172.16.211.100DNS (BIND) + NTP (Chrony) server
devbox172.16.211.99Dev machine
k8s-1 … k8s-5172.16.211.11 – .15Kubernetes nodes (1 master + 4 workers, built in Part 3)
Gateway172.16.211.2VMware Fusion NAT gateway
  • Lab domain: dev.geekcoding101local.com
  • Subnet: 172.16.211.0/24

info: This DNS server does not replace CoreDNS. CoreDNS runs inside Kubernetes for service discovery. This one is a plain local DNS server so the VMs on the private network can resolve each other’s hostnames. That way the master and workers talk by name, which makes cluster management much smoother.


Step 1: Clone the localserver VM from the base image

Clone with vmrun

Run these on your Mac. Adjust VMDIR to your own VMware Fusion folder:

Terminal window
VMDIR="/Users/geekcoding101.com/Virtual Machines.localized"
# Full clone of the base image
vmrun clone "$VMDIR/baseimage-rocky9.vmwarevm/baseimage-rocky9.vmx" \
"$VMDIR/localserver.vmwarevm/localserver.vmx" full
# Rename it from "Clone of baseimage-rocky9" to "localserver"
sed -i '' 's/displayName = "Clone of baseimage-rocky9"/displayName = "localserver"/' \
"$VMDIR/localserver.vmwarevm/localserver.vmx"
# Confirm the new display name
grep displayName "$VMDIR/localserver.vmwarevm/localserver.vmx"

By default a clone shows up in VMware Fusion as Clone of baseimage-rocky9. The sed line renames it to localserver. (sed -i '' is the macOS form of in-place editing.)

Make Fusion see the new VM

You’ll probably need to run a scan in VMware Fusion before the new VM appears in the library.

VMFusion scan new vm

Step 2: Give localserver its own hostname and IP

  1. Stop the baseimage VM and start localserver. The clone still has the base image’s IP, so running both at once causes a network conflict.
  2. SSH in as root using the base VM’s IP: 172.16.211.3.
  3. Create the input file for the /opt/share_tools/bin/configure_vm.yml playbook we built in Part 1. Save this as /opt/share_tools/init_data/localserver_vm_input.json:
{
"hostname": "localserver",
"ip": "172.16.211.100",
"subnet": "24",
"gateway": "172.16.211.2",
"dns1": "8.8.8.8",
"dns2": "8.8.4.4",
"domain": "dev.geekcoding101local.com",
"ansible_key_path": "~/.ssh/ansible_ed25519",
"ssh_key_path": "~/.ssh/ssh_ed25519"
}
  1. Run the playbook from the VMware Fusion console, not over SSH. It changes the IP, which will drop your SSH session and can leave the run half-finished.
Terminal window
ansible-playbook /opt/share_tools/bin/configure_vm.yml \
-e "input_file_path=/opt/share_tools/init_data/localserver_vm_input.json"

Based on the input file, the playbook will:

  • Set the hostname to localserver
  • Configure the network interface (ens160 in my case) with 172.16.211.100
  • Generate SSH keys for both Ansible and normal SSH
  • Apply the other base settings

When it finishes, SSH back in using the new IP, 172.16.211.100.


Step 3: Set up the DNS server with BIND

Install BIND

Terminal window
dnf update -y
dnf install bind -y

We need to edit three files:

FilePurpose
/etc/named.confMain BIND config: listen addresses, forwarders, zone definitions
/var/named/dev.geekcoding101local.com.zoneForward zone: hostname → IP
/var/named/211.16.172.in-addr.arpa.zoneReverse zone: IP → hostname

/etc/named.conf

Compared with the file the Rocky package ships, the changes are:

  • listen-on now includes 172.16.211.100
  • allow-query is set to any
  • A forwarder is added
  • The two lab zones are added at the bottom
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { 127.0.0.1; 172.16.211.100; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { any; };
forwarders {
8.8.8.8; # Google's DNS as a fallback
};
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion yes;
dnssec-validation yes;
managed-keys-directory "/var/named/dynamic";
geoip-directory "/usr/share/GeoIP";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
/* https://fedoraproject.org/wiki/Changes/CryptoPolicy */
include "/etc/crypto-policies/back-ends/bind.config";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "dev.geekcoding101local.com" IN {
type master;
file "/var/named/dev.geekcoding101local.com.zone";
allow-update { none; };
};
zone "211.16.172.in-addr.arpa" IN {
type master;
file "/var/named/211.16.172.in-addr.arpa.zone";
allow-update { none; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

tip: allow-query { any; }; is fine on a private lab network that only lives on your laptop. If this server could ever be reached from outside, lock it down to allow-query { localhost; 172.16.211.0/24; };. The warning in the file above about DNS amplification is exactly why.

Forward zone: /var/named/dev.geekcoding101local.com.zone

$TTL 86400
@ IN SOA localserver.dev.geekcoding101local.com. root.dev.geekcoding101local.com. (
2024010103 ; Serial
3600 ; Refresh
1800 ; Retry
1209600 ; Expire
86400 ) ; Minimum TTL
@ IN NS localserver.dev.geekcoding101local.com.
; Local server (DNS + NTP)
localserver IN A 172.16.211.100
; Kubernetes nodes
k8s-1 IN A 172.16.211.11
k8s-2 IN A 172.16.211.12
k8s-3 IN A 172.16.211.13
k8s-4 IN A 172.16.211.14
k8s-5 IN A 172.16.211.15
; Dev machine
devbox IN A 172.16.211.99

Reverse zone: /var/named/211.16.172.in-addr.arpa.zone

$TTL 86400
@ IN SOA localserver.dev.geekcoding101local.com. root.dev.geekcoding101local.com. (
2024010103 ; Serial
3600 ; Refresh
1800 ; Retry
1209600 ; Expire
86400 ) ; Minimum TTL
@ IN NS localserver.dev.geekcoding101local.com.
; PTR Records
11 IN PTR k8s-1.dev.geekcoding101local.com.
12 IN PTR k8s-2.dev.geekcoding101local.com.
13 IN PTR k8s-3.dev.geekcoding101local.com.
14 IN PTR k8s-4.dev.geekcoding101local.com.
15 IN PTR k8s-5.dev.geekcoding101local.com.
99 IN PTR devbox.dev.geekcoding101local.com.
100 IN PTR localserver.dev.geekcoding101local.com.

warning: Skip the reverse zone and reverse lookups fail like this:

❯ nslookup 172.16.211.100
** server can't find 100.211.16.172.in-addr.arpa: NXDOMAIN

Check syntax, then start BIND

Check both zone files before you restart anything:

Terminal window
named-checkconf
named-checkzone dev.geekcoding101local.com /var/named/dev.geekcoding101local.com.zone
named-checkzone 211.16.172.in-addr.arpa /var/named/211.16.172.in-addr.arpa.zone

named-checkzone command pass on kubernetes cluster to test DNS server
named-checkzone command pass on kubernetes cluster to test DNS server

The named service runs as the named user, so make sure it can read the zone files:

Terminal window
chown root:named /var/named/dev.geekcoding101local.com.zone /var/named/211.16.172.in-addr.arpa.zone
chmod 640 /var/named/dev.geekcoding101local.com.zone /var/named/211.16.172.in-addr.arpa.zone

Restart and check the service:

Terminal window
systemctl enable --now named
systemctl restart named
systemctl status named

named service status for DNS server
named service status for DNS server

info: You might see an Unable to fetch DNSKEY error in the status output. You can ignore it here; we don’t need DNSKEY for this lab.

Test it

On localserver, test forward and reverse lookups:

Terminal window
nslookup localserver.dev.geekcoding101local.com 127.0.0.1
nslookup k8s-1.dev.geekcoding101local.com 127.0.0.1
nslookup 172.16.211.100 127.0.0.1

DNS server nslookup test localserver in kubernetes environment
DNS server nslookup test localserver in kubernetes environment

Bump the serial every time you edit a zone

warning: Every time you modify a zone file, increment its serial number. The format is YYYYMMDD##. For example, if the current serial is 2024010101 and you’re making a second change the same day, change it to 2024010102. Then restart named (or run rndc reload).


Step 4: Set up the NTP server with Chrony

All the nodes run on one laptop, so I want them to sync time from localserver instead of each one depending on the internet. Kubernetes components such as TLS certificates and etcd don’t like clock skew between nodes.

info: Chrony is an implementation of the Network Time Protocol (NTP). It’s an alternative to ntpd, the reference implementation of NTP.

Install it:

Terminal window
dnf install chrony -y

Edit /etc/chrony.conf. The key change is one allow line so the lab subnet can sync from this server:

...
# Let the lab VMs use this server for time
allow 172.16.211.0/24
# Optional: keep serving time to the lab if the internet drops
local stratum 10
...

local stratum 10 is optional. It lets localserver keep answering the other VMs when it can’t reach its upstream servers. That’s the whole point if your laptop goes offline.

Start the service:

Terminal window
systemctl enable --now chronyd
systemctl restart chronyd
systemctl status chronyd

Verify the sources:

Terminal window
chronyc sources -v

Example output:

.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? 65-100-46-164.dia.static> 1 6 377 16 -33ms[ -33ms] +/- 47ms
^? ntp3.radio-sunshine.org 2 6 377 15 -81ms[ -81ms] +/- 120ms
^? server.slakjd.com 3 6 377 16 -71ms[ -71ms] +/- 44ms
^? kjsl-fmt2-net.fmt2.kjsl.> 2 6 377 16 -65ms[ -65ms] +/- 8139us
^? localserver.dev.geekcodi> 0 6 0 - +0ns[ +0ns] +/- 0ns

Give Chrony a few minutes after a restart and run the command again. Once it has settled, one source should be marked * (current best). You can also run chronyc tracking to see the current offset.


Step 5: Open the firewall (if firewalld is running)

Rocky Linux 9 ships with firewalld. If it’s active on your base image, the other VMs can’t reach DNS (port 53) or NTP (UDP 123) until you open them:

Terminal window
firewall-cmd --permanent --add-service=dns --add-service=ntp
firewall-cmd --reload

Then test from another VM on the subnet, such as devbox:

Terminal window
nslookup k8s-1.dev.geekcoding101local.com 172.16.211.100
nslookup 172.16.211.11 172.16.211.100

Troubleshooting

SymptomLikely causeFix
server can't find ... in-addr.arpa: NXDOMAINNo reverse zoneAdd the 211.16.172.in-addr.arpa zone and its file
Unable to fetch DNSKEY in named statusDNSSEC trust anchor lookupsSafe to ignore in this lab
Zone edits don’t take effectSerial not incrementedBump the serial, then restart named or run rndc reload
SSH drops while running the playbookThe playbook changes the IPRun it from the VMware Fusion console
Other VMs can’t query localserverfirewalld, or listen-on missing the VM IPOpen dns/ntp in firewalld; check listen-on includes 172.16.211.100
named fails to load a zoneFile permissions or syntaxRun named-checkzone and check the file is readable by named

Wrapping up

localserver is now running DNS and NTP for the lab. 🚀

In Part 3, I will:

  • Configure a Kubernetes base image
  • Spin up the master node and 4 worker nodes from that image
  • Set up the K8s master node
  • Join the worker nodes to the cluster

Stay tuned, and let’s keep this cluster rolling! 🔥

The full Ultimate Kubernetes Tutorial series

Each post builds on the last, so make sure you haven’t missed one:

  • Part 1: The networking plan, my goals for the Kubernetes setup, and how to prepare a base VM image for the cluster.
  • Part 2: Local DNS and NTP server (this post).
  • Part 3: A streamlined Kubernetes cluster setup with Flannel: one master and 4 worker nodes ready for real workloads.
  • Part 4: NodePort vs ClusterIP: the key differences, use cases, and when to choose each for internal and external service access.
  • Part 5: ExternalName and LoadBalancer, plus load testing with the tool hey.

FAQ

Does this DNS server replace CoreDNS? No. CoreDNS handles service discovery inside Kubernetes. This BIND server only resolves the VMs’ hostnames on the private 172.16.211.0/24 network.

Why do I need a reverse zone? Without it, looking up an IP such as 172.16.211.100 returns NXDOMAIN. The reverse zone maps IPs back to hostnames.

Is the “Unable to fetch DNSKEY” error a problem? Not for this lab. You can ignore it.

Why isn’t my zone change showing up? You probably forgot to bump the serial number. Use the YYYYMMDD## format, increase it on every edit, and restart named or run rndc reload.

Why run a local NTP server for a lab? All the nodes run on one laptop. Syncing them from localserver keeps their clocks consistent, and Kubernetes components like certificates and etcd are sensitive to clock skew.

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.

Keep reading

All posts