DEV Community

Charles Scholle
Charles Scholle

Posted on

Local Kubernetes Playground Made Easy

Hey there! Are you looking to play around with Kubernetes but don't want to go through the hassle of setting up a cluster on the cloud? Well, you're in luck! In this blog post, I'm going to show you how to set up a local environment for experimenting with Docker and Kubernetes using k3d. We'll make sure you have all the necessary tools installed, and then I'll walk you through the process of creating a cluster and experimenting with it. So grab a cup of coffee (or tea) and let's dive in!

Background

If you are a developer and want to learn how to deploy applications to a cluster, getting a cluster up an running can be a daunting task in it's own rights. There are many ways to do it: spinning up local virtual machines and configuring from scratch or using tools like minikube, etc. You may not care for the pain of setting up and configuring a cluster, and if that is you, then the quickest way that I have found is using k3d.

Pre-requisites

For this tutorial, you'll need to have Docker, kubectl, and k3d installed.
If you are on a Mac and have brew installed, you can simply run the install command(s) for anything missing:

brew install docker 
brew install kubernetes-cli 
brew install k3d
Enter fullscreen mode Exit fullscreen mode

Otherwise, see the respective docs for install instructions:

Create a Cluster

Here is the best part! k3d is a wrapper around k3s and can set up your entire cluster using Docker in no time. It should be noted that this is not intended for production, but it is intended for tinkerers, learning, and exam prep. Here's an example command and then we will break it down:

k3d cluster create my-cluster --agents 3
Enter fullscreen mode Exit fullscreen mode

This sets up a new cluster with one server for the control plan and 3 worker nodes. After a short period, you should be able to run kubectl get node and them: one server (control-plane/master) as well as 3 worker nodes, e.g.:

❯ kubectl get node                         
NAME                      STATUS   ROLES                  AGE    VERSION
k3d-my-cluster-agent-0    Ready    <none>                 108s   v1.24.6+k3s1
k3d-my-cluster-server-0   Ready    control-plane,master   116s   v1.24.6+k3s1
k3d-my-cluster-agent-2    Ready    <none>                 112s   v1.24.6+k3s1
k3d-my-cluster-agent-1    Ready    <none>                 112s   v1.24.6+k3s1
Enter fullscreen mode Exit fullscreen mode

If you want to blow it away, simply run k3d cluster delete my-cluster.

At this point, you have a functioning Kubernetes cluster that you can spin up or delete in seconds, running locally with no external dependencies!

Conclusion

While there are many ways to spin up a Kubernetes cluster, k3d is by far one of the simplest.

Top comments (0)