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'.
I'm using below ansible play to remove it:
- name: Unistalling postgres from K8s
block:
- name: Removing Statefulsets & Service from "{{postgres_namespace}}"
action:
shell kubectl -n "{{postgres_namespace}}" delete statefulsets "{{postgres_release_name}}" && kubectl -n "{{postgres_namespace}}" delete service "{{postgres_release_name}}"-service
register: postgres_removal_status
- debug:
var: postgres_removal_status.stdout_lines
but getting this error:
Error from server (NotFound): statefulsets.apps \"postgres\" not found
This is the result from kc -n postgres-ns get all
:
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 <none> 5432/TCP 57s`
`service/postgres-postgresql-headless ClusterIP None <none> 5432/TCP 57s`
`NAME READY AGE`
`statefulset.apps/postgres-postgresql 1/1 57s
Can some one help me here?
Thanks in advance.
Error from server (NotFound): statefulsets.apps \"postgres\" not found
This says that you want to delete a statefulset which name is postgress
, But from your get all
command the name of statefulset is statefulset.apps/postgres-postgresql
. You need to update delete statefulsets "{{postgres_release_name}}"-postgresql
or pass correct value of postgres_release_name
?