How to cleanup database in kubernetes after service is deleted?

9/16/2019

Consider the following things are already satisfied.
1. The maria-db is running in separate pod and is pre-installed.
2. When we deploy a new service it is able to connect to maria-db and create SCHEMA in it.

But the final requirement is when the service is deleted then it should cleanup the SCHEMA. I have tried writing a job with post-delete tag.

-- Gokul Manoj Dhoot
kubernetes

1 Answer

9/17/2019

So just a thought, you could possible do this by using a Admission Control i.e your logic could possible be along the lines of:

Delete Pod Requested --> Hits Addmission Control --> Addmission Controller Removes Schema --> Pod Deleted

However this would be a lot of custom code and you would need a way to identify the Schema that that particular service has created in the DB.

-- Spazzy757
Source: StackOverflow