How to reset docker-for-mac v2.1.0.0 kubernetes from the command line?

8/8/2019

I am constantly creating new clusters for development and I dislike going into "Troubleshooting" every time to reset the cluster.

Is there a quicker way to do this?

-- dax99
docker
kubernetes

1 Answer

8/8/2019

Quickest way I can think of is to blat the kubernetes etcd data.

You will need to have "Show system containers" turned on in Docker.

Please note, this is super destructive and not thoroughly tested (other than to see if it runs). There's probably horrible side effects from using it. Docker for Desktop maintains a lot more state on disk than just etcd. There's also an rm -rf in there which you should never trust someone on the internet telling you to run! But here we go...

This will:

  • Find the k8s_etcd_etcd-* container and remove all etcd data from it.
  • Force delete all containers with a name of k8s_*.

  • Docker for Desktop will reinitialise the containers.

  • Kubernetes will reinitialise the etcd database (hopefully)

One liner:

docker exec $(docker ps -q --filter 'name=k8s_etcd_etcd-*' -l) rm -rf /var/lib/etcd/member \
  && docker rm -f $(docker ps -q --filter 'name=k8s_*')

or as a script with a bit more output:

#!/bin/bash -uex

etcd_container=$(docker ps -q --filter 'name=k8s_etcd_etcd-*' -l)
docker exec "$etcd_container" rm -rf /var/lib/etcd/member;
all_k8s_containers=$(docker ps -q --filter 'name=k8s_*')
docker rm -f $all_k8s_containers
-- Matt
Source: StackOverflow