Marshall Tigerus
Marshall Tigerus

Reputation: 3764

Kubernetes Secret is persisting through deletes

I'm trying to clean up some leftover data from a failed deployment of rabbitmq. As such, I have 3 secrets that were being used by rabbit services that never fully started. Whenever I try to delete these using kubectl delete secret they get recreated with a similar name instantly (even when using --force).

I do not see any services or pods that are using these secrets, so there shouldn't be any reason they are persisting.

Example of what happens when I delete: enter image description here

Upvotes: 13

Views: 14947

Answers (2)

Tomasz Bartkowiak
Tomasz Bartkowiak

Reputation: 14958

In my case the reason was simpler - the secret was created within a namespace i.e. with

kubectl create secret docker-registry <secret> --namespace <namespace>

in order to delete such a secret you need to append the namespace name to the kubectl delete secret command:

kubectl delete secret <secret-name> -n <namespace-name>

Upvotes: 0

Marshall Tigerus
Marshall Tigerus

Reputation: 3764

The reason they wouldn't delete is because they were associated with a service account.

I found this by looking at their yaml files, which mentioned they were for a service account.

I then ran

kubectl get serviceaccounts

which returned a list of accounts that had identical names. After running

kubectl delete serviceaccounts <accountName>

The secrets removed themselves.

However, if they do not, you can still get and delete them with

kubectl get secrets
kubectl delete secret <secret name>

If you do not see the item in question, you may want to append --all-namespaces to see "all" of them, as by default it looks at the top level of your kubernetes environment.

Upvotes: 29

Related Questions