Part 2 – Hosting this blog on my own server – Creating a K3D cluster

k3d logo

Prerequisites for running K3D

I chose to run k3d on a linux OS — in my case I run arch linux (which is harder to install than Ubuntu), but any flavour should work.  So install the OS on bare metal, as this will remove complexities with virtualization. Generally

  • Install base OS, you don’t need a desktop UI XWindows setup, terminal access suffices.  Not having UI will reduce bloat, be more secure, and reduce CPU/resource use.
  • Configure network, its best to have an ethernet connection directly to your router.
  • Configure Disks/Partitions.
  • Setup non-root user.
  • Install basic utils & add non-root user to sudo group.
    top-level packages, install each with sudo pacman -Sy
    
    git
    base-develop
    dhcp
    dhcpd
    systemd-networkd
    networkmananger
    apt-transport-https
    bc
    bind-tools
    ca-certificates
    curl
    curl
    dhcpcd
    dialog
    dnsutils
    docker
    exa
    expat
    expat
    fail2ban
    figlet
    gettext
    ghc-static
    git-lfs
    gnupg2
    gptfdisk
    groff
    iproute2
    jdk-openjdk
    jdk-openjdkn
    jq
    jre-openjdk
    less
    libcurl-gnutls
    lsusb
    mc
    neofetch
    net-tools
    netctl
    ntfs-3g
    openssh
    openssl
    python
    python-pip
    python-pipx
    python-software-properties
    rsync
    sudo
    tmux
    top
    ttext
    unzip
    usbutils
    wget
    zip
    zlib 
    zsh-syntax-highlighting

     

  • Optional  but useful – configure zsh/oh-my-zsh.
  • Install kubectl , make sure to pick a version that is compatible with k3d, currently at 1.27.
  • Install Helm, instructions are here.
  • Make sure docker is installed (its in the list above), and make it work without sudo.
  • Install the k3d command line tool according to the github project instructions.
Creating a k3d cluster on the target machine.

Run this command to create the cluster with load balancers, and two agents and one server.  Exposing the api port locally allows you to contact the control plane from a different machine

k3d cluster create k3d-cluster  \
    --port "80:80@loadbalancer"  \
    --port "443:443@loadbalancer"  \
    --agents 2  \
    --kubeconfig-update-default  \
    --servers 1  \
    --api-port 6443:6443

Note that this will overrwite any existing ~/.kube/k8s-kubeconfig.yaml, potentially containing info you want to keep. The k3d github site has more info on running and installing k3d, but the above should work.

At this point, kubectl should work, and the command

kubectl get ns

should return a list of namespaces on your new cluster.

Next steps

We now have a cluster, it will need a bit of configuration to be useful, before we try to install wordpress. But before that a bit more wireless router port-forwarding and dhcp server magic is needed to make sure incoming traffic makes it to your new server.

Leave a Reply