Single Node Kubernetes with Docker Desktop

You can run Single-node Linux Kubernetes clusters with full Linux command line support using Docker Desktop and Windows WSL2.  Docker Desktop makes this simple.

This is probably obvious to everyone. I wrote this to capture the commands to use as a future reference.

There is another article that discusses 
  • Creating a multi-node Kubernetes Cluster on a single machine using Kind http://joe.blog.freemansoft.com/2020/07/multi-node-kubernetes-with-kind-and.html

Windows 10 / 11 - WSL2 - Docker

The simplest way to run Kubernetes Windows 10 is with the Docker Desktop and WSL2 integration.  Docker will prompt to enable WSL2 integration during installation if you are running a late enough version of Windows 10 or any Windows 11.

Prerequisites

Docker is installed with WSL2 integration enabled.  The docker command operates correctly when you type a docker command in a WSL linux command prompt.

Install, Enable and Verify


Install Docker
Enable Kubernetes
  • Open the Settings Panel.  
  • Enable Kuberentes 
  • Press Apply and Restart
  • Wait a while - Docker Desktop will download the required images.
    • You can verify the download is working with docker images



... ...
The Docker Desktop status bar will change to 

View the K8s Cluster status using kubectl cluster-info.  You should see the master and DNS are running
$ kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Kubernetes desktop acts as a single-node Kubernetes cluster. You can see this with with the kubectl get-nodes command
$ kubectl get nodes
NAME             STATUS   ROLES     AGE    VERSION
docker-desktop   Ready    control-plane,master   3d4h   v1.22.4
See all services via kubectl get all or kubectl get services
* kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   3d4h
See all services in all namespaces including K8s ones with kubectl get all --all-namespaces
$ kubectl get all --all-namespaces
NAMESPACE     NAME                                         READY   STATUS    RESTARTS   AGE
docker        pod/compose-78f95d4f8c-d2kqn                 1/1     Running   0          3d4h
docker        pod/compose-api-6ffb89dc58-b88bz             1/1     Running   0          3d4h
kube-system   pod/coredns-5644d7b6d9-6nm4t                 1/1     Running   0          3d4h
kube-system   pod/coredns-5644d7b6d9-wzmmf                 1/1     Running   0          3d4h
kube-system   pod/etcd-docker-desktop                      1/1     Running   0          3d4h
kube-system   pod/kube-apiserver-docker-desktop            1/1     Running   0          3d4h
kube-system   pod/kube-controller-manager-docker-desktop   1/1     Running   0          3d4h
kube-system   pod/kube-proxy-cz7pw                         1/1     Running   0          3d4h
kube-system   pod/kube-scheduler-docker-desktop            1/1     Running   0          3d4h
kube-system   pod/storage-provisioner                      1/1     Running   1          3d4h
kube-system   pod/vpnkit-controller                        1/1     Running   0          3d4h

NAMESPACE     NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes    ClusterIP   10.96.0.1        <none>        443/TCP                  3d4h
docker        service/compose-api   ClusterIP   10.108.194.113   <none>        443/TCP                  3d4h
kube-system   service/kube-dns      ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   3d4h

NAMESPACE     NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR                 AGE
kube-system   daemonset.apps/kube-proxy   1         1         1       1            1           beta.kubernetes.io/os=linux   3d4h

NAMESPACE     NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
docker        deployment.apps/compose       1/1     1            1           3d4h
docker        deployment.apps/compose-api   1/1     1            1           3d4h
kube-system   deployment.apps/coredns       2/2     2            2           3d4h

NAMESPACE     NAME                                     DESIRED   CURRENT   READY   AGE
docker        replicaset.apps/compose-78f95d4f8c       1         1         1       3d4h
docker        replicaset.apps/compose-api-6ffb89dc58   1         1         1       3d4h
kube-system   replicaset.apps/coredns-5644d7b6d9       2         2         2       3d4h


Kubernetes for Docker Desktop automatically raises the API server, Kubernetes master.  
        https://kubernetes.docker.internal:6443/
I don't know how this differers from 127.0.0.1You should get a 403 forbidden if you GET from that endpoint.
Make the API server visible to the network by starting the kubectl proxy
joe@z820:~$ kubectl proxy
Starting to serve on 127.0.0.1:8001
Point browser at http://127.0.0.1:8001
{
"paths": [
"/api",
"/api/v1",
"/apis",
"/apis/",
"/apis/admissionregistration.k8s.io",
"/apis/admissionregistration.k8s.io/v1",
"/apis/admissionregistration.k8s.io/v1beta1",
"/apis/apiextensions.k8s.io",
"/apis/apiextensions.k8s.io/v1",
"/apis/apiextensions.k8s.io/v1beta1",
"/apis/apiregistration.k8s.io",
"/apis/apiregistration.k8s.io/v1",
"/apis/apiregistration.k8s.io/v1beta1",
"/apis/apps",
"/apis/apps/v1",
...

Troubleshooting

Kubernetes won't start after Windows 11 upgrade.
  • I was unable to create and start my K8S after upgrading to Windows 11.  Kubernetes never started.  The only way I could fix it was
    1. Uninstall Docker Desktop
    2. Restart
    3. Install Docker Desktop
    4. Enable Kubernetes
  • Kubectl cluster-info returned nothing after K8s was enabled.
    • I had to close and re-open my terminal window. It had been opened prior to enabling K8S

Originally Created 2021/10

Comments

Popular posts from this blog

Installing the RNDIS driver on Windows 11 to use USB Raspberry Pi as network attached

Understanding your WSL2 RAM and swap - Changing the default 50%-25%

Almost PaaS Document Parsing with Tika and AWS Elastic Beanstalk