Block ads with Pi-hole and Kubernetes

santisbon - Mar 14 '23 - - Dev Community

While there are browser extensions and apps you can use to block ads on your desktop and mobile, they require installing them individually on each of your devices. And that's assuming there's an app available for the device and OS in question.

Wouldn't it be better to also block ads at the router level? All those smart TVs, set-top boxes, game consoles, VR headsets, smart speakers, smart thermostats, robot vacuums, security cameras, doorbells, and other IoT devices love chatting with metrics/ad services. Let's put a stop to that by deploying a DNS server that will block requests to known ad servers.

Raspberry Pi is a tiny computer you can use as a desktop, smart home hub, robot brains, media center, and more. If you have been thinking about setting up a homelab, a Raspberry Pi is a great place to start at an extremely low cost. They are in high demand but this site can help you find one.

MicroK8s is a lightweight distribution of Kubernetes (K8s) for container orchestration. We'll also use Helm, a package manager for K8s, for easy deployment.

Pi-hole is a DNS sinkhole that protects your devices from unwanted content, without installing any client-side software. It's installed in one place and blocks ads for your entire home network.

When you're done you'll have an admin interface for all your K8s workloads:
k8s

And another for your Pi-hole stats:
pi-hole

Let's get started! All the details are here:

GitHub logo santisbon / pi-hole-k8s

Deploy Pi-hole to a Kubernetes cluster on a Raspberry Pi.

Network-wide ad blocking with Pi-hole, Kubernetes, and Raspberry Pi

Prerequisites

  1. Set up your Raspberry Pi with a static IP.
  2. Install and configure MicroK8s (or any other lightweight Kubernetes distribution) on your Pi.

Install

  1. Prepare your Pi's storage
    # On your Pi
    sudo mkdir -p /etc/pihole
    sudo mkdir -p /etc/dnsmasq.d
    Enter fullscreen mode Exit fullscreen mode
  2. If installing from source, grab the code
    # On your Pi
    CHART="./piholechart"
    
    git clone https://github.com/santisbon/pi-hole-k8s.git && cd pi-hole-k8s
    nano $CHART/values.yaml
    # edit the values
    Enter fullscreen mode Exit fullscreen mode
    Or if installing from the repository:
    # On your Pi
    helm repo add santisbon https://santisbon.github.io/charts/
    CHART="santisbon/pihole"
    Enter fullscreen mode Exit fullscreen mode
  3. Install the Helm chart which will enforce the installation order. Replace parameters with a secure password and the static IP of your Pi if you didn't do it through the values.yaml file. If using MicroK8s type the commands as microk8s helm and microk8s kubectl
    # On your Pi
    RELEASE=pihole
    NAMESPACE=pihole-n
    helm install 
    Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . .
Terabox Video Player