Building Your Own Kubernetes Playground: A Step-by-Step Guide to Setting up a Home Lab with Ingress and DNS

Gareth Hunt
6 min readMar 8, 2023

If you’re looking to master Kubernetes, then you’ll need to set up a home lab with an ingress and DNS. It’s the perfect way to practice and improve your skills. I’ve had so many people ask me about the best way to set up their home lab, and I’m happy to help! Whether you prefer to use Nginx ingress or something else, I’m here to guide you through the process. Together, we’ll not only create a Kubernetes playground for you, but we’ll also prepare you for the more complex tasks you’ll encounter in the future, like service mesh and mTLS. So, let’s get started and have some fun along the way!

Prerequisites:

  • Before we start, it’s important to have a Unix terminal set up. Whether you’re using a Mac, Linux, or WSL (Windows Subsystem for Linux), you’ll need this in place to proceed. I will make sure to be inclusive of every OS so nobody is confused! You can still follow this guide if you are using a different terminal but you may have to do some googling if stuff doesn’t work as expected.
  • I am currently using a fresh installation of Windows for this to ensure that I don’t miss a single step. To install WSL you can open up command prompt and type:
wsl --install 
  • Once it has installed, you will need to reboot your machine (brb while I do exactly that!)
    Once it reboots it will take “A few minutes” to install. Set up a username and password and you’re all set!

Installing Kubernetes

Now what you use is complete preference. I have tried them all, minikube, docker desktop; you name it! I have come to the (very biased) decision that Rancher Desktop is #1. Not only is it novice friendly but it integrates very easily with multiple cluster in your kube config. This is especially useful if you are installing this on a work machine and have something like KTX installed. If you don’t understand that sentence, don’t worry, you can completely ignore it.

  1. Go to the Rancher Desktop site and download it for your OS.
    Mac users, remember to choose the right chipset. If you’re lucky enough to own an M1-M2 Mac, then you have an Apple Silicon chip. If you don’t then you have an Intel chip.
  2. Install Rancher Desktop. You may need to restart your machine again (Sorry, last time I promise!). I would recommend completing step 3 and then restarting your machine.
  3. Select the Kubernetes version you wish to install. You may want to use the latest stable version but if you are currently working for a company that uses Kubernetes, then I would highly suggest installing that version instead. You can view the Kubernetes change log if you want to understand why it’s so important the your version matches up. I will be installing Kubernetes version v1.22.17 and I will be using containerd.
  4. Your version of Kubernetes will begin downloading. If you are like me and have terrible internet then you can click around while it is downloading if you want to get comfortable with what it can do.
  5. you can visit install tools to install kubectl. Remember to install the version of kubectl that matches your cluster. for example, I installed v1.22.17.
  6. Go back to the Rancher Desktop application. If you are using WSL then you will need to go to File -> Preferences and make sure you have enabled it enabled. It will need to restart the cluster.
  7. run the command kubectl get ns to see all the namespaces available on the cluster.
  8. Congratulations! You have a Kubernetes cluster setup 🎉

Installing the Ingress

As mentioned previously, everyone has a preference for this. We will be using Istio for this. Why? Because it’s the most powerful Ingress you can use for Kubernetes. While it isn’t the most “novice friendly” ingress, it is certainly the one you want to learn if you want to do more complex tasks further down the line, such as service mesh. Again, you may want to install the same ingress that your company uses but this is entirely up to you!

  1. inside your terminal run: curl -L https://istio.io/downloadIstio | sh -
  2. Make sure to add istio to your path as output suggests. In WSL this is controlled by your .bashrc file. Open up your .bashrc file using your favourite text editor and at the bottom of the file, paste in the output. For example I would add: export PATH=”$PATH:/home/USERNAME)/istio-1.17.1/bin"
    (I would give the command for vim but if you haven’t used it before you will end up in vim HELL!).
  3. run the command to install Istio:
istioctl install --set profile=demo -y 

4. Create yourself a namespace by running: kubectl create ns istiodemo. then run kubectl label namespace istiodemo istio-injection=enabled. This will add a label to your created namespace and it will do Istio injection for the demo application we are about to install.

5. run kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.17/samples/bookinfo/platform/kube/bookinfo.yaml — namespace istiodemo to install the demo application to your namespace.

6. if you now run kubectl get pods -n istiodemo you will see the pods start to spin up. You may notice that it was waiting for 0/2 to be ready instead of 0/1. This is because Istio uses a sidecar proxy called Envoy. If this makes absolutely no sense to you then don’t worry. Istio works out of the box.

7. Inside Rancher, on the left hand side, there should be a button called “Port Forwarding” if you enable the product page for port-forwarding and go to localhost:<portNumber> in your browser, it will automatically port forward the pod for you (which if you know Kubernetes at all is SUPER useful!). The Simple Bookstore App should load and it will worth like any other application. Have a click around to see what it can do!

8. Istio has some really cool “Extras” that are very simple to install. One of them that I have found most impressive is their tracing addon called Kiali. You can see a list of all the addons here. They have things like Grafana and Prometheus that are out of the box and easy to get started with, but that will be a whole other tutorial!

Congratulations! You have an Ingress set up on your Kubernetes cluster!🎉

Installing the DNS

Ok if you’ve made it this far, then well done! If you’ve skipped the rest of the sections and have made it here then welcome!

So we have Kubernetes setup and we have an ingress setup. We now need to ensure we have DNS setup. There are multiple ways of doing this but I like to use an actual DNS name and setup the hosts file.

  1. run kubectl delete svc -n kube-system traefik to remove the default load balancer service
  2. inside rancher click File -> Preferences and on the left hand side click Kubernetes. Untick the box which says “Enable Traefik”. Your Kubernetes cluster will restart.
  3. re-run the command:
istioctl install --set profile=demo -y

4. run `kubectl get svc -n istio-system` and look for the type Loadbalancer that has an external IP.

5. Open up notepad as an administrator (that bit is important) and open the file “C:\Windows\System32\drivers\etc\hosts” (if you use another OS do this in your hosts file). At the bottom of the line add <external_ip> productpage.istiodemo.com

6. Save this to a file called ingress.yaml :

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: istiodemo
annotations:
kubernetes.io/ingress.class: istio
name: ingress
spec:
rules:
- host: productpage.istiodemo.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: productpage
port:
number: 9080

run kubectl apply -f ingress.yaml to install it.

7. Once saved, you should now be able to access your new product page!

Congratulations on setting up your local Kubernetes cluster with Istio and DNS enabled!

If you have any questions, message me on LinkedIn or put a comment below and I will try and help as much as possible :) This is my first medium article so apologies if the formatting breaks anything!

Enjoy learning Kubernetes and let me know how you get on!

--

--

Gareth Hunt

Senior Platform Engineer who wants to make devops fun for everyone!