<p>I want to remove all the pods from a specific namespace through Ansible Play. Here , I'm trying to delete all the postgres pods from a namespace 'postgres-ns'.</p>

<p>I'm using below ansible play to remove it:</p>

<pre><code>- name: Unistalling postgres from K8s
  block:
     - name: Removing Statefulsets &amp; Service from  "{{postgres_namespace}}"
      action:
        shell kubectl -n "{{postgres_namespace}}" delete statefulsets "{{postgres_release_name}}" &amp;&amp; kubectl -n "{{postgres_namespace}}" delete service "{{postgres_release_name}}"-service
      register: postgres_removal_status
    - debug:
        var: postgres_removal_status.stdout_lines
</code></pre>

<p>but getting this error:</p>

<pre><code>Error from server (NotFound): statefulsets.apps \"postgres\" not found
</code></pre>

<p>This is the result from <code>kc -n postgres-ns get all</code>:</p>

<pre><code>NAME                        READY   STATUS    RESTARTS   AGE`

`pod/postgres-postgresql-0   1/1     Running   0          57s`

`NAME                                   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE`

`service/postgres-postgresql            ClusterIP   10.108.64.70   &lt;none&gt;        5432/TCP   57s`

`service/postgres-postgresql-headless   ClusterIP   None           &lt;none&gt;        5432/TCP   57s`

`NAME                                   READY   AGE`

`statefulset.apps/postgres-postgresql   1/1     57s
</code></pre>

<p>Can some one help me here?</p>

<p>Thanks in advance.</p>

Shuvodeep Ghosh
<blockquote>
  <p><code>Error from server (NotFound): statefulsets.apps \"postgres\" not found</code></p>
</blockquote>

<p>This says that you want to delete a statefulset which name is <code>postgress</code>, But from your <code>get all</code> command the name of statefulset is <code>statefulset.apps/postgres-postgresql</code>. You need to update <code>delete statefulsets "{{postgres_release_name}}"-postgresql</code> or pass correct value of <code>postgres_release_name</code>?</p>
