When my Kubernetes pods get terminated (due to restarting or completely stopping), I would like to invoke some kind of a lifecycle hook that will notify me of the termination through email. Something like the following:
onTermination:
args:
- '/bin/sh'
- '-c'
- |
<smtp login and send email script>
How I can get an email when my pod is restarted or stop in Kubernetes?
Only way I know that you can get an email if there is something wrong with Cluster/Node/Pod are monitoring tools.
You can use i.e paid software with free trial like sysdig or datadog. If you want to learn Kubernetes metrics you can use kube-state-metrics with Prometheus (AlertManager) and i.e Grafana as backend.
Here you have some steps which may be useful.
You can also check InfluxDB or Stackdriver as data source.
Tutorials which may help you
https://devopscube.com/setup-prometheus-monitoring-on-kubernetes/
https://itnext.io/kubernetes-monitoring-with-prometheus-in-15-minutes-8e54d1de2e13