Enable Kubernetes in Docker Desktop: A Step‑by‑Step Guide
This guide walks you through installing Docker Desktop, configuring registry mirrors, running a PowerShell script to preload required images, enabling the built‑in Kubernetes cluster, and accessing the Kubernetes Dashboard, providing a complete solution for quickly setting up a local K8s environment on Windows or macOS.
Enable Kubernetes in Docker Desktop
Overview
As the de‑facto standard for container orchestration, Kubernetes is the foundation of modern applications, but many beginners get stuck at the first hurdle: obtaining a working K8s environment. Building a full cluster locally requires substantial hardware, so the simplest approach is to use the built‑in Kubernetes provided by Docker Desktop on Windows or macOS.
Step by Step
First, install Docker Desktop (just click Next). For better performance, use WSL 2 as the backend; the latest Docker Desktop defaults to WSL 2. The example uses version 3.3.1, which includes Kubernetes v1.19.7.
Choose a host backend:
WSL 2: enable "Windows Subsystem for Linux" in Windows Features, then install a Linux distribution from the Microsoft Store. 适用于 Linux 的 Windows 子系统 Hyper‑V: enable Hyper‑V in Windows Features (note that Hyper‑V may conflict with other VM software).
Hyper-V2.1 Enable K8s Service
Because Docker Hub mirrors are slow, configure Docker Engine to use faster registry mirrors. Add the following JSON to the registry-mirrors field (using Docker’s official and USTC mirrors):
{ "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn", "https://registry.docker-cn.com" ], "insecure-registries": [], "debug": false, "experimental": false, "features": { "buildkit": true } }After saving the configuration, restart Docker Desktop.
Clone the k8s-for-docker-desktop repository and locate the load_images.ps1 PowerShell script. This script pulls the required images from Alibaba Cloud, ensuring the image versions match the built‑in Kubernetes version, then loads them into Docker.
If PowerShell blocks script execution, run: Set-ExecutionPolicy RemoteSigned Once the script finishes, the images listed in images.properties will be present locally.
Open Docker Desktop settings, go to the Kubernetes page, check "Enable Kubernetes", and click "Apply & Restart". After a minute or two, the K8s cluster will start.
2.2 Enable Dashboard
After the cluster is up, you can deploy the Kubernetes Dashboard for a visual interface. In the cloned repository, apply the kubernetes-dashboard.yaml file: kubectl apply -f kubernetes-dashboard.yaml Check the deployment and pod status:
kubectl get deployment -n kubernetes-dashboard
kubectl get pods -n kubernetes-dashboardStart a proxy to access the dashboard: kubectl proxy Retrieve the token for login:
$TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1]
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"
echo $TOKENOpen the dashboard at:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
