In this section, we will setup CloudWatch alarm and send notification using SNS when a Pod restarts more than once in a 5 minute period.
Get the name of the ecsdemo-frontend pod using the following command
kubectl get pods NAME READY STATUS RESTARTS AGE ecsdemo-crystal-6b45547688-tzvw2 1/1 Running 0 8d ecsdemo-frontend-7f7644d5d5-tk72w 1/1 Running 3 8d ecsdemo-nodejs-744d497fdc-9hwgz 1/1 Running 0 8d
Kill the pod using the following command after replacing the placeholder string with the name of the ecsdemo-frontend pod obtained from the command above. Wait for the pod to restart, and then kill it again. Do all this within 5 minutes so the alarm can be triggered.
kubectl exec -it <NAME_OF_THE_ECSDEMO_FRONT_END_POD> -c ecsdemo-frontend -- /bin/sh -c "kill 1"
Navigate to CloudWatch Alarms page and you should be able to see the alarm firing off as shown below
If your email is subscribed to the SNS topic, you will also see an email notification as shown below