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

<p>Is there a quicker way to do this? </p>

daxmc99
<p>Quickest way I can think of is to blat the kubernetes etcd data.</p>

<p>You will need to have "Show system containers" turned on in Docker.</p>

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

<p>This will:</p>

<ul>
<li>Find the <code>k8s_etcd_etcd-*</code> container and remove all etcd data from it.</li>
<li>Force delete all containers with a name of <code>k8s_*</code>.<br></li>
<li>Docker for Desktop will reinitialise the containers.<br></li>
<li>Kubernetes will reinitialise the etcd database (hopefully)</li>
</ul>

<p>One liner:</p>

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

<p>or as a script with a bit more output:</p>

<pre><code>#!/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
</code></pre>
