<p>Being new to the K8s, I am trying to clean up the whole namespace after running some tests on a Windows 10 machine. In short, I thought it would be as easy as running kubectl.exe delete deployment but the deployments are created back after a second and I don't know how to get rid of them. See the followings for the details of what I did:  </p>

<p><em><code>1.kubectl get deployments,rs</code></em> (to see what we already have)</p>

<pre><code>NAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE AGE
deployment.extensions/postgresql   1         1         1            1           18m
deployment.extensions/redis        1         1         1            1           16m
NAME                                         DESIRED   CURRENT   READY     AGE  
replicaset.extensions/postgresql-c8cb9fff6   1         1         1         18m
replicaset.extensions/redis-5678477b7c       1         1         1         16m
</code></pre>

<p><em><code>2. kubectl scale deployment redis --replicas=0</code></em> (Scale down the deployment)  </p>

<pre><code>deployment.extensions "redis" scaled
</code></pre>

<p><em><code>3. kubectl get deployments,rs</code></em> (Check again how it looks) </p>

<pre><code>NAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/postgresql   1         1         1            1           21m
deployment.extensions/redis        0         0         0            0           19m
NAME                                         DESIRED   CURRENT   READY     AGE
replicaset.extensions/postgresql-c8cb9fff6   1         1         1         21m
replicaset.extensions/redis-5678477b7c       0         0         0         19m
</code></pre>

<p><em><code>4. kubectl delete deployment.extensions/redis</code></em> (Delete the deployment) </p>

<pre><code>deployment.extensions "redis" deleted
</code></pre>

<p><em><code>5. kubectl get deployments,rs</code></em> (Check again and see that it is back!)</p>

<pre><code>NAME                               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/postgresql   1         1         1            1           23m
deployment.extensions/redis        1         1         1            1           27s  
NAME                                         DESIRED   CURRENT   READY     AGE
replicaset.extensions/postgresql-c8cb9fff6   1         1         1         23m
replicaset.extensions/redis-5678477b7c       1         1         1         27s
</code></pre>

<p><em><code>6. kubectl.exe get events</code> (Looking into the events):</em><br>
Among other things I can see "Scaled down replica set redis-5678477b7c to 0" and then "Scaled up replica set redis-5678477b7c to 1" which looks like it was never actually deleted but immediately scaled up again after the delete command was executed. </p>

<p>Not sure what I am missing but have already checked a couple of other posts like <a href="https://stackoverflow.com/questions/40686151/kubernetes-pod-gets-recreated-when-deleted">Kubernetes pod gets recreated when deleted</a> and <a href="https://stackoverflow.com/questions/47128586/how-to-delete-all-resources-from-kubernetes-one-time">How to delete all resources from Kubernetes one time?</a> but neither one worked for me. </p>

<p>Forgot to say that the K8s cluster is managed by the Docker Desktop.</p>

Ramin Toussi
<ol>
<li><p>Use <code>kubectl delete deployment &lt;the name of deployment &gt;</code></p></li>
<li><p>If you need to clean up whole namespace , use <code>kubectl delete namespace &lt;namespace-name&gt;</code></p></li>
<li><p>Then re-create the same namespace by <code>kubectl create ns</code> command , if you need the same namespace.</p></li>
<li><p>You can also clean up the namespace by using --all options with objects:</p></li>
</ol>

<p>e.g </p>

<pre><code>   kubecetl delete deployment --all
   kubecetl delete statefulset --all
   kubectl delete pvc --all
   kubectl delete secrets --all
   kubectl delete service --all
</code></pre>

<p>and so on.</p>

<p>As pointed out by <strong>@David Maze</strong>, you're deleting the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer">ReplicaSet</a> instead of the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployment that's managing it</a>.</p>

<p>From the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">documentation</a>:</p>

<blockquote>
  <p>You can define Deployments to create new ReplicaSets</p>
</blockquote>

<p>The Deployment will automatically create and manage a ReplicaSet to control the pods. You need to delete the Deployment to erase it's managed resources.</p>
