DEV Community

Kaushik Mitra
Kaushik Mitra

Posted on Fully Autonomous

Setting up a Kubernetes Cluster Locally with Docker Desktop

Recently I've started diving deeper into Kubernetes. If you are starting your cloud-native or container orchestration journey, the sheer number of tools out there can feel overwhelming—Minikube, Kind, K3s, MicroK8s, and cloud-managed options.

When you just want to get your hands dirty without spending money on cloud resources or configuring complex virtual machines, Docker Desktop offers the simplest starting point.

Did you know that Docker Desktop comes with a fully functional single-node Kubernetes cluster built right into it? With a single checkbox, you can spin up a control plane and node right on your machine!

In this guide, we'll walk through enabling Kubernetes in Docker Desktop, verifying your environment with kubectl, and testing our local cluster.


Why Docker Desktop for Local Kubernetes?

For beginners and everyday local development, Docker Desktop has a few distinct advantages:

  1. Zero Extra Virtualization Setup: If you already use Docker Desktop on macOS, Windows (via WSL2), or Linux, you don't need to install VirtualBox, Hyper-V extras, or special network bridges.
  2. Shared Docker Daemon: Container images built locally via docker build are instantly accessible to your local Kubernetes cluster without needing to push to Docker Hub or a remote registry first!
  3. Low Friction: Starting, stopping, or resetting your entire cluster takes just one click from the UI.

Prerequisites

Before we start, make sure you have:

  • Docker Desktop installed and running.
  • A terminal (Bash, Zsh, or PowerShell).
  • Recommended: At least 4GB to 8GB of RAM allocated to Docker Desktop (check Settings -> Resources).

📦 Source Code: You can find the complete source code, Dockerfiles, and Kubernetes manifests for this entire series on GitHub: MitraKumar/kube-prac-calculator-app.


Step 1: Enable Kubernetes in Docker Desktop

By default, Docker Desktop runs only the Docker engine. Enabling Kubernetes is straightforward:

  1. Open Docker Desktop.
  2. Click on the Settings gear icon in the top-right corner.
  3. In the left navigation menu, click on Kubernetes.
  4. Check the box labeled Enable Kubernetes.
  5. (Optional) You can leave "Show system containers" unchecked for now to keep your docker ps output clean.
  6. Click Apply & restart.

Step 2: Verify kubectl and Cluster Connection

kubectl is the official command-line tool for communicating with a Kubernetes cluster. Docker Desktop automatically installs and configures kubectl for you.

Let's open our terminal and verify our client version:

kubectl version --client
Enter fullscreen mode Exit fullscreen mode

You should see output similar to:

Client Version: v1.31.0
Kustomize Version: v5.4.2
Enter fullscreen mode Exit fullscreen mode

Checking Configured Contexts

Kubernetes uses a "context" to know which cluster and user account to communicate with. Docker Desktop creates a context named docker-desktop.

Run:

kubectl config get-contexts
Enter fullscreen mode Exit fullscreen mode

Output:

CURRENT   NAME             CLUSTER          AUTHINFO         NAMESPACE
*         docker-desktop   docker-desktop   docker-desktop   
Enter fullscreen mode Exit fullscreen mode

If the asterisk (*) is not next to docker-desktop, switch to it explicitly:

kubectl config use-context docker-desktop
Enter fullscreen mode Exit fullscreen mode

Step 3: Inspect Your Local Node and Control Plane

Now that kubectl is pointed at your local cluster, let's verify cluster health:

kubectl cluster-info
Enter fullscreen mode Exit fullscreen mode

Output:

Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Enter fullscreen mode Exit fullscreen mode

Let's check the cluster nodes:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Output:

NAME             STATUS   ROLES           AGE   VERSION
docker-desktop   Ready    control-plane   1d    v1.31.0
Enter fullscreen mode Exit fullscreen mode

Notice that docker-desktop acts as both the control-plane and the worker node. It is in the Ready status, meaning it is ready to schedule workloads!


Step 4: Test Driving the Cluster

To ensure everything is working as expected, let's deploy a quick standalone Nginx pod:

kubectl run test-nginx --image=nginx --port=80
Enter fullscreen mode Exit fullscreen mode

Check the pod status:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Output:

NAME         READY   STATUS    RESTARTS   AGE
test-nginx   1/1     Running   0          15s
Enter fullscreen mode Exit fullscreen mode

Let's forward a local port to test traffic reaching the pod:

kubectl port-forward pod/test-nginx 8080:80
Enter fullscreen mode Exit fullscreen mode

Now open another terminal or your browser at http://localhost:8080 (or run curl http://localhost:8080). You should see the welcome page for Nginx!

Once verified, press Ctrl+C to stop the port-forward and delete the test pod:

kubectl delete pod test-nginx
Enter fullscreen mode Exit fullscreen mode

Useful Tips for Docker Desktop Kubernetes

  1. How Local Images Work (The Magic Trick): When running Docker Desktop Kubernetes, your local Docker engine and Kubernetes share the same image store. If you build an image locally:
   docker build -t my-app:1.0 .
Enter fullscreen mode Exit fullscreen mode

You can specify image: my-app:1.0 in your Kubernetes pod manifest with imagePullPolicy: Never or imagePullPolicy: IfNotPresent, and Kubernetes will use your local image without needing any push or registry setup!

  1. Resetting the Cluster: If something goes wrong while experimenting, you don't have to troubleshoot for hours. Go back to Docker Desktop Settings -> Kubernetes and click Reset Kubernetes Cluster. In seconds, you get a clean slate.

Conclusion & What's Next

Setting up Kubernetes locally shouldn't be intimidating. Docker Desktop gives you an instant, robust environment right out of the box with zero fuss.

In the next post, we will build a real multi-service calculator application using Node.js & Express, package it into containers, and explore the core building blocks of Kubernetes: Namespaces, Pods, and ClusterIP Services.

Please leave a comment below if you found this guide helpful or if you run into any issues during your setup!

Top comments (0)