delete kubernetes cluster on docker-for-desktop OSX

In recent Docker Edge versions for Mac ( 2.1.7 ) Preferences design has been changed. Now you can reset Kubernetes cluster and other docker aspects by switching to the bug plane in the top right of Preferences window:

Note: You are able to reset Kubernetes cluster only if it's enabled. If you uncheck "Enable Kubernetes" checkbox, "Reset Kubernetes cluster" button becomes inactive.

enter image description here

For convenience "Reset Kubernetes cluster" is also present on the Kubernetes tab in the main Preferences plane:

enter image description here


To reset Docker-desktop Kubernetes cluster using command line, put the following content to a file (dd-reset.sh) and mark it executable ( chmod a+x dd-reset.sh )

#!/bin/bash

dr='docker run -it --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i'

${dr} sh -c 'export PATH=$PATH:/containers/services/docker/rootfs/usr/bin:/containers/services/docker/rootfs/usr/local/bin:/var/lib/kube-binary-cache/ && \
if [ ! -e /var/run/docker.sock ] ; then ln -s /containers/services/docker/rootfs/var/run/docker.sock /var/run/docker.sock ; fi && \
kube-reset.sh'

sleep 3

echo "cluster resetted. restarting docker-desktop..."
osascript -e 'quit app "Docker"'

open --background -a Docker
echo "docker-desktop started. Wait 3-5 mins for kubernetes to start."

Explanation:

This method uses internal scripts from Docker-desktop VM. To make it work, some preparation of user environment is required.

I wasn't able to start Kubernetes cluster using kube-start.sh script from inside the VM, so I've used MacOS commands to restart Docker application instead.

This method works even if your Kubernetes cluster is not enabled in Docker preferences at the moment, but it's required to enable Kubernetes at least once to use the script.

It was tested on Docker Edge for MacOS v2.2.2.0 (43066)
There is no guarantee that it will be compatible with earlier or later versions.

This version of Docker uses kubeadm to initialize Kubernetes cluster. Scripts are located in the folder /containers/services/docker/rootfs/usr/bin:

  • kube-pull.sh (brings kubernetes binaries to VM)
  • kube-reset.sh (runs kube-stop.sh and do kubeadm reset + some rm stuff)
  • kube-restart.sh (runs kube-stop.sh and kube-start.sh)
  • kube-start.sh (runs kube-pull.sh and kubelet.sh)
  • kube-stop.sh (kills kubelet and kube-apiserver processes, and all k8s containers)
  • kubeadm-init.sh (initializes Kubernetes cluster)
  • kubelet.sh (runs kubeadm-init.sh and starts kubelet binary)

Cluster configuration is located in the file /containers/services/docker/lower/etc/kubeadm/kubeadm.yaml

Resources used:

  • Restart Docker from command line
  • Use nsenter in priviledged container

Tear down Kubernetes in Docker for OS X is quite an easy task.

Go to Preferences, open Reset tab, and click Reset Kubernetes cluster.

enter image description here

All object that have been created with Kubectl before that will be deleted.

You can also reset docker VM image (Reset disk image) and all settings (Reset to factory defaults) or even uninstall Docker.