I'm creating a Multi-Tenancy Kubernetes infrastructure. I created a Helm Chart with my app, and now I need automate the helm chart installation when a new namespace is created.
For example, when the namespace client1
is create I need to run helm install myrepo/myapp --name client1
.
How can i get the new namespace creation event? And the namespace name?
You can either keep running a script which executes kubectl get namespace
every since a while and compares the current result with the old result. When you find out a new namespace created, you can then execute helm install myrepo/myapp --name client1
. Or you can run an application in your cluster. What the application does is basically listing all namespaces in the cluster, comparing the current with the cached, if a new namespace found, then call helm client to install your app. For more information, if you are using golang, I would recommend you to use kubernetes client-go to get the list of namespaces in the cluster and you can refer to the open resource project pipeline for the helm client-go part to install your app.