In my previous post, I set up a Raspberry Pi cluster with Rancher. In this post, I’m going to show you how to set up PiHole using Rancher.

What is PiHole?

PiHole is a free ad blocking software that lets you block ads from your entire network. This means no more annoying ads and trackers, helping maintain your privacy. If this walkthrough helps you set up a PiHole successfully, I’d recommend donating to their cause: https://pi-hole.net/donate/.

Before We Start

First, create a new namespace in the Rancher UI. Navigate to the cluster you created in the previous post and click on the Namespaces tab at the top. Click Add Project and type in the name of the project — in my example, I used pihole.

Next, before we install and start PiHole, we need to make sure the system we’re installing the PiHole container on has a DNS reference. Install resolvconf:

sudo apt install resolvconf

Start and enable the service:

sudo systemctl start resolvconf.service
sudo systemctl enable resolvconf.service

Edit the resolv.conf file:

sudo vi /etc/resolvconf/resolv.conf.d/head

Add the following line (this can be any DNS service):

nameserver 1.1.1.1

Reboot the RPi node:

sudo reboot now

Check the resolv.conf:

sudo cat /etc/resolv.conf

The output should look something like this:

nameserver 1.1.1.1
nameserver 127.0.0.53
search lan

To set up my workload for PiHole, I referenced the PiHole GitHub repository: https://github.com/pi-hole/docker-pi-hole/blob/master/docker_run.sh

Back in your terminal session on your RPi node, create a directory on each node at the following location:

/mnt/pihole

Creating a Workload

Back in the Rancher interface, navigate to Resources > Workloads and click Deploy.

Create the workload with the following settings:

  • Name: pihole
  • Docker Image: pihole/pihole:latest
  • Namespace: pi-hole
  • Port Mapping:
    • dns-tcp → 53 / TCP / HostPort / 53
    • dns-udp → 53 / UDP / HostPort / 53
    • pihole-http → 80 / TCP / HostPort / 8001
  • Environment Variables:
    • TZAmerica/Los_Angeles
    • DNS11.1.1.1
    • DNS210.0.1
    • ServerIP192.168.86.101 (use whatever your RPi server IP is)
  • Volumes:
    • Volume Name: pihole-etc / Type: Bind-Mount / Node path: /mnt/pihole/etc-pihole/ / Mount point: /etc/pihole/
    • Volume Name: pihole-dnsmasq / Type: Bind-Mount / Node path: /mnt/pihole/etc-dnsmasq.d/ / Mount point: /etc/dnsmasq.d/
  • Scaling/Upgrade Policy: Kill ALL pods, then start new

Click Launch and you should see your container starting up.

Logging In and Setting a Password

Click on the pi-hole-xxxxxx pod. This will take you to the container view. Click the three dots on the right-hand side of the Containers section and click View Logs. This will show you the password that was set for PiHole during installation.

Since I prefer not to use passwords set by someone else, I recommend clicking Execute Shell in the same window. This drops you right into the container’s shell. Type the following command:

pihole -a -p

Enter your new password and confirm. Then log into your PiHole dashboard by opening a browser and navigating to the IP.

Navigate to the server IP and port you defined earlier in your environment variables and port mapping — in my case http://192.168.86.101:8001. Log in with your newly defined password and you’re in!

Wrapping Up

Update the list of blocked domains by navigating to Tools > Update Gravity, then click the big Update button.

Once the domain list has been updated, enable PiHole by clicking the Enable button on the sidebar.

Now that PiHole is updated and enabled, we need to point our DNS to the PiHole service. I wanted to start by testing this on one computer before switching my DNS network-wide. Go to your network settings (depending on whether you use Windows, Linux, or Mac) where you would normally assign a static IP address for your network adapter. Statically assign the DNS server to the IP of the PiHole — in my case 192.168.86.101. For instructions on setting this up on your specific OS, check out: https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245.

You’re all set — now check out a website you know has a ton of ads and test it out!


Let me know if you have any questions or found this walkthrough helpful.