Since I started working with computers I always loved the idea of a homelab, a safe space to mess with stuff, break stuff and sometimes learn a few things along the way.

Back when I was trying to land my first tech job my homelab was a bunch of noisy Cisco switches and routers. Along the way I discovered GNS3 and eventually those physical switches and routers were virtualized on my Sony Vaio VGN-N31Z with it’s Core 2 Duo, 2GB of RAM and 128GB of spinning rust.

A few years later when I started working with Windows my homelab transitioned into a Windows Server 2012 R2 virtual machine running on VirtualBox. It didn’t take long to realize that if I wanted to run more than just a couple of VMs at the same time I would need some serious hardware. So I ended up breaking the bank on a desktop running the free version of VMware ESXi packed with an Intel i7, 64GB of RAM and a bunch of SSDs.

Fast forward again and with everything moving to the public cloud my homelab shifted to an AWS account. What was once a capital expense with finite resources became an operational expense with “limitless” capabilities.

These days my homelab is a vintage Dell Latitude with an Intel i3, 16GB of RAM and a 1TB SSD running Debian. Here is how I set it up..


Foundation

This guide begins after we have selected the hardware, downloaded the Debian 13 ISO, created a bootable USB drive, and completed a minimal installation with only “standard system utilities” and “SSH server” selected.

At this point, we should know the machine’s IP address on the network and have successfully connected to it via SSH using the user account we created during the installation process.

Let’s get started..

  • switch to the root user..

    su -
    
  • install a few packages..

    apt update && apt upgrade -y && apt install -y \
      ansible \
      apt-transport-https \
      bash-completion \
      btm \
      buildah \
      ca-certificates \
      curl \
      ethtool \
      git \
      gnupg \
      jq \
      unzip \
      vim \
      htop \
      nmap \
      rsync \
      skopeo \
      strace \
      tcpdump \
      tmux \
      tree \
      uuid-runtime \
      yq
    
  • install and configure sudo..

    USERNAME="user"
    
    apt install -y sudo
    usermod -a -G sudo ${USERNAME}
    
  • update some kernel parameters..

    cat << 'EOF' >> /etc/sysctl.conf
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    kernel.printk = 1 4 1 7
    fs.inotify.max_user_instances = 16384
    EOF
    sysctl -p
    
  • create a systemd service to apply our updated kernel parameters at boot..

    cat << 'EOF' >> /etc/systemd/system/sysctl.service
    [Unit]
    After=network.target
    
    [Service]
    Type=oneshot
    ExecStart=/sbin/sysctl -p
    
    [Install]
    WantedBy=multi-user.target
    EOF
    systemctl daemon-reload
    systemctl enable sysctl.service
    
  • configure ssh..

    USERNAME="user"
    
    install -d -m 0700 -o ${USERNAME} -g ${USERNAME} /home/${USERNAME}/.ssh
    install -m 0600 -o ${USERNAME} -g ${USERNAME} /dev/null /home/${USERNAME}/.ssh/config
    install -m 0600 -o ${USERNAME} -g ${USERNAME} /dev/null /home/${USERNAME}/.ssh/authorized_keys
    su - ${USERNAME} -c "ssh-keygen -t ed25519 -f /home/${USERNAME}/.ssh/id_ed25519 -N '' -C ''"
    
  • create a few files and directories to keep our stuff organized..

    USERNAME="user"
    
    install -d -m 0775 -o ${USERNAME} -g ${USERNAME} /home/${USERNAME}/.tls
    install -d -m 0775 -o ${USERNAME} -g ${USERNAME} /home/${USERNAME}/.scripts
    install -m 0644 -o ${USERNAME} -g ${USERNAME} /dev/null /home/${USERNAME}/.bash_aliases
    
  • change the way the bash prompt looks..

    USERNAME="user"
    
    printf '%s\n' 'export PS1="\[\e[37m\][\[\e[93m\]\w\[\e[37m\]] \[\e[0m\]"' >> "/home/${USERNAME}/.bashrc"
    printf '%s\n' 'export PS1="\[\e[37m\][\[\e[91m\]\w\[\e[37m\]] \[\e[0m\]"' >> "/root/.bashrc"
    

Building Blocks

Now that we have established the foundation, we can begin adding our building blocks.

Since I work as a Site Reliability Engineer the tools I use include the following..

  • docker

    USERNAME="user"
    
    curl -L https://download.docker.com/linux/debian/gpg | gpg --dearmor > /etc/apt/keyrings/docker.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "${VERSION_CODENAME}") stable" > /etc/apt/sources.list.d/docker.list
    apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    usermod -aG docker ${USERNAME}
    systemctl daemon-reload
    systemctl enable docker.service
    systemctl start docker.service
    

    By default Docker binds published ports to all interfaces (0.0.0.0) making containers accessible from anywhere. I prefer the opposite, containers should be private unless explicitly exposed.

    systemctl stop docker.service
    cat << 'EOF' > /etc/docker/daemon.json
    {
      "ip": "127.0.0.1",
      "metrics-addr": "0.0.0.0:9323"
    }
    EOF
    systemctl start docker.service
    
  • gvisor

    curl -L https://gvisor.dev/archive.key | gpg --dearmor > /etc/apt/keyrings/gvisor.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/gvisor.gpg] https://storage.googleapis.com/gvisor/releases release main" > /etc/apt/sources.list.d/gvisor.list
    apt update && apt install -y runsc
    
  • kubectl

    TEMP_DIR="$(mktemp -d)"
    
    curl -Lo ${TEMP_DIR}/kubectl "https://dl.k8s.io/release/$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
    install -m 0755 -o root -g root ${TEMP_DIR}/kubectl /usr/local/bin/kubectl
    kubectl completion bash > /etc/bash_completion.d/kubectl
    
  • k9s

    TEMP_DIR="$(mktemp -d)"
    K9S_VERSION="$(curl -Ls https://api.github.com/repos/derailed/k9s/releases/latest | jq -r .tag_name)"
    
    curl -Lo ${TEMP_DIR}/k9s_Linux_amd64.tar.gz https://github.com/derailed/k9s/releases/download/${K9S_VERSION}/k9s_Linux_amd64.tar.gz
    tar -xzf ${TEMP_DIR}/k9s_Linux_amd64.tar.gz --directory ${TEMP_DIR}
    install -m 0755 -o root -g root ${TEMP_DIR}/k9s /usr/local/bin/k9s
    k9s completion bash > /etc/bash_completion.d/k9s
    
  • minikube

    TEMP_DIR="$(mktemp -d)"
    
    curl -Lo ${TEMP_DIR}/minikube_latest_amd64.deb https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
    dpkg -i ${TEMP_DIR}/minikube_latest_amd64.deb
    minikube completion bash > /etc/bash_completion.d/minikube
    

    When Minikube starts it checks for a Docker network with the same name and creates it automatically if it doesn’t exist. By creating this network manually we can define a custom IP range and make the node IPs predictable.

    docker network rm minikube > /dev/null 2>&1
    docker network create "minikube" --driver="bridge" --subnet="10.20.30.0/24" --gateway="10.20.30.1"
    
  • haproxy

    A simple reverse proxy to easily access HTTP workloads running on Minikube. It listens on ports 80 and 443 of the system and forwards connections to the Minikube network.

    HAPROXY_LISTEN_ADDRESS="0.0.0.0"
    
    apt install -y haproxy
    systemctl daemon-reload
    systemctl enable haproxy.service
    systemctl stop haproxy.service
    echo 'EXTRAOPTS="-q"' >> /etc/default/haproxy
    cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
    cat << EOF > /etc/haproxy/haproxy.cfg
    global
      log /dev/log local0 info
    
    defaults
      log global
      timeout client 30000
      timeout connect 5000
      timeout server 30000
    
    frontend stats
      mode http
      bind ${HAPROXY_LISTEN_ADDRESS}:8404
      stats enable
      stats uri /
      stats refresh 30s
      no log
    
    frontend metrics
      mode http
      bind ${HAPROXY_LISTEN_ADDRESS}:8405
      http-request use-service prometheus-exporter
      no log
    
    frontend haproxy-http
      mode tcp
      bind ${HAPROXY_LISTEN_ADDRESS}:80
      default_backend minikube-http
      option tcplog
    
    frontend haproxy-https
      mode tcp
      bind ${HAPROXY_LISTEN_ADDRESS}:443
      default_backend minikube-https
      option tcplog
    
    backend minikube-http
      mode tcp
      server minikube 10.20.30.2:31080 check
      server minikube-m02 10.20.30.3:31080 check
      server minikube-m03 10.20.30.4:31080 check
      server minikube-m04 10.20.30.5:31080 check
      server minikube-m05 10.20.30.6:31080 check
    
    backend minikube-https
      mode tcp
      server minikube 10.20.30.2:31443 check
      server minikube-m02 10.20.30.3:31443 check
      server minikube-m03 10.20.30.4:31443 check
      server minikube-m04 10.20.30.5:31443 check
      server minikube-m05 10.20.30.6:31443 check
    EOF
    haproxy -c -f /etc/haproxy/haproxy.cfg
    systemctl start haproxy.service
    
  • helm

    curl -L https://packages.buildkite.com/helm-linux/helm-debian/gpgkey | gpg --dearmor > /etc/apt/keyrings/helm.gpg
    echo "deb [signed-by=/etc/apt/keyrings/helm.gpg] https://packages.buildkite.com/helm-linux/helm-debian/any any main" > /etc/apt/sources.list.d/helm.list
    apt update && apt install -y helm
    helm completion bash > /etc/bash_completion.d/helm
    
  • terraform

    USERNAME="user"
    
    curl -L https://apt.releases.hashicorp.com/gpg | gpg --dearmor > /etc/apt/keyrings/hashicorp.gpg
    echo "deb [signed-by=/etc/apt/keyrings/hashicorp.gpg] https://apt.releases.hashicorp.com $(. /etc/os-release && echo "${VERSION_CODENAME}") main" > /etc/apt/sources.list.d/hashicorp.list
    apt update && apt install -y terraform
    echo 'complete -C /usr/bin/terraform terraform' >> /home/${USERNAME}/.bashrc
    
  • opentofu

    USERNAME="user"
    
    curl -L https://get.opentofu.org/opentofu.gpg > /etc/apt/keyrings/opentofu.gpg
    curl -L https://packages.opentofu.org/opentofu/tofu/gpgkey | gpg --dearmor > /etc/apt/keyrings/opentofu-repo.gpg
    cat << 'EOF' > /etc/apt/sources.list.d/opentofu.list
    deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
    deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
    EOF
    apt update && apt install -y tofu
    echo 'complete -C /usr/bin/tofu tofu' >> /home/${USERNAME}/.bashrc
    
  • grafana

    curl -L https://apt.grafana.com/gpg.key | gpg --dearmor > /etc/apt/keyrings/grafana.gpg
    echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" > /etc/apt/sources.list.d/grafana.list
    apt update && apt install -y grafana
    systemctl daemon-reload
    systemctl enable grafana-server.service
    systemctl start grafana-server.service
    

    The web interface is on port 3000, login with admin as the username and password.

  • act

    TEMP_DIR="$(mktemp -d)"
    ACT_VERSION="$(curl -Ls https://api.github.com/repos/nektos/act/releases/latest | jq -r .tag_name)"
    
    curl -Lo ${TEMP_DIR}/act_Linux_x86_64.tar.gz https://github.com/nektos/act/releases/download/${ACT_VERSION}/act_Linux_x86_64.tar.gz
    tar -xzf ${TEMP_DIR}/act_Linux_x86_64.tar.gz --directory ${TEMP_DIR}
    install -m 0755 -o root -g root ${TEMP_DIR}/act /usr/local/bin/act
    

Tactical Enhancements

This part of the guide covers things that are nice to have but they are not strictly necessary.

A nice upgrade is to register a domain. With a domain we can set up DNS records that take advantage of the global DNS network and also issue valid TLS certificates.

After registering a domain through a registrar, we create a Cloudflare account and transfer the domain’s DNS management to it. On Cloudflare, we configure A records that point to the local IP of our system (domain.xyz A 192.168.1.2, *.domain.xyz A 192.168.1.2) and create an API token with the “DNS Write” permission policy.

With the API token we can run a Bash script that uses acme.sh to generate a wildcard TLS certificate and save it to the ~/.tls directory of our system.

Show Bash script
#!/bin/bash

# This script generates a wildcard TLS certificate using acme.sh and the Cloudflare API.

set -e
set -u
set -o pipefail

### script variables

USERNAME=""             # your debian username - "user"
DOMAIN_NAME=""          # your domain name - "domain.xyz"
CLOUDFLARE_API_TOKEN="" # your cloudflare api token - "6_z3K2aFdSpIq6VBkaz3i4xHT_uYiBNmDftWNZ-K"

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    docker
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

VARIABLES=(
    USERNAME
    DOMAIN_NAME
    CLOUDFLARE_API_TOKEN
)
for i in "${VARIABLES[@]}"; do
    if [[ -z "${!i:-}" ]]; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s variable \"%s\" is not set\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### acme.sh

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

TLS_DIR="/home/${USERNAME}/.tls"

docker run \
  --rm \
  --env CF_Token="${CLOUDFLARE_API_TOKEN}" \
  --volume "${TEMP_DIR}:/acme.sh/tls" \
  neilpang/acme.sh:latest \
  acme.sh \
  --dns dns_cf \
  --domain "${DOMAIN_NAME}" \
  --domain "*.${DOMAIN_NAME}" \
  --domain "*.dev.${DOMAIN_NAME}" \
  --domain "*.ops.${DOMAIN_NAME}" \
  --issue \
  --keylength ec-256 \
  --server letsencrypt \
  --cert-file /acme.sh/tls/tls.crt \
  --key-file /acme.sh/tls/tls.key \
  --ca-file /acme.sh/tls/ca.crt \
  --fullchain-file /acme.sh/tls/fullchain.crt

FILES_MISSING="false"
FILES=(
    tls.crt
    tls.key
    ca.crt
    fullchain.crt
)
for i in "${FILES[@]}"; do
    if [[ ! -f "${TEMP_DIR}/${i}" ]]; then
        FILES_MISSING="true"
        printf "%sERROR:%s file \"%s\" was not created\n" "${RED}" "${RESET}" "${i}"
    fi
done
if [[ "${FILES_MISSING}" == "true" ]]; then
    exit 1
fi

install -d -m 0700 -o "${USERNAME}" -g "${USERNAME}" "${TLS_DIR}"

install -m 644 -o "${USERNAME}" -g "${USERNAME}" "${TEMP_DIR}/tls.crt" "${TLS_DIR}/tls.crt"
install -m 600 -o "${USERNAME}" -g "${USERNAME}" "${TEMP_DIR}/tls.key" "${TLS_DIR}/tls.key"
install -m 644 -o "${USERNAME}" -g "${USERNAME}" "${TEMP_DIR}/ca.crt" "${TLS_DIR}/ca.crt"
install -m 644 -o "${USERNAME}" -g "${USERNAME}" "${TEMP_DIR}/fullchain.crt" "${TLS_DIR}/fullchain.crt"

cat "${TEMP_DIR}/fullchain.crt" "${TEMP_DIR}/tls.key" > "${TEMP_DIR}/tls.pem"
install -m 600 -o "${USERNAME}" -g "${USERNAME}" "${TEMP_DIR}/tls.pem" "${TLS_DIR}/tls.pem"

printf "%sINFO:%s certificate files saved to \"%s\"\n" "${GREEN}" "${RESET}" "${TLS_DIR}"

Another useful upgrade to consider is setting up remote access. We could rent a VPS and set up WireGuard tunnels between our devices but this adds latency. A better option is to use something like Nebula where the VPS can act as a broker and not as a relay. Another valid option would be to use Cloudflare tunnels. However, the simplest option is to use a managed service like Tailscale or ZeroTier which can handle everything for us.

The last upgrade to consider is configuring wake-on-lan. Most systems support this feature but it must be enabled in both the BIOS and on the network interface. We use ethtool to check if wake-on-lan is enabled on our system’s ethernet interface..

INTERFACE="" # the name of the ethernet interface - enp2s0

ethtool ${INTERFACE} | grep "Wake-on:"

If the output is Wake-on: g it means that wake-on-lan is already enabled, if not we do the following to enable it..

INTERFACE="" # the name of the ethernet interface - enp2s0

cat << EOF > /etc/network/interfaces.d/${INTERFACE}
auto ${INTERFACE}
iface ${INTERFACE} inet dhcp
  ethernet-wol g
EOF
systemctl restart networking.service
ethtool ${INTERFACE} | grep "Wake-on:"

If we pair wake-on-lan with a Raspberry Pi on the same network and a remote access solution we will be able to power on our system and control it from anywhere.


Ongoing Maintenance

Setting things up once is fine but without updates we are stuck with a snapshot of the system from the day it was installed.

Running apt update && apt upgrade -y regularly will keep both the system and most of our tools up to date. To update kubectl, k9s, minikube and act we can simply run their installation commands again.

The TLS certificate is valid for 90 days and we can issue a fresh certificate by running the script again.


Closing Thoughts

Allright, we saw a bunch of things and touched many topics but one thing we did not cover is security.

So is it secure? Well, we prioritized convenience over security in a few areas but at the end of the day this is a homelab not a production system, it will never store sensitive data and if someone breaks into my house to steal my stuff my crusty old hardware will be the least of my concerns.

At the end of the day this is all about experimentation and learning so take what works for you and make it your own.