2 min read
If we need to investigate why a container keeps restarting, a good place to start is taking a look at the logs when it crashes. Since Kubernetes will automatically restart a failed container, if we use kubectl logs we will get the logs of the restarted container instead of the one that have crashed:
$ kubectl logs ampa-7d98c84675-dpzjw -c ampa [2021-10-15 14:20:41 +0000]  [INFO] Starting gunicorn 20.0.4 [2021-10-15 14:20:41 +0000]  [INFO] Listening at: http://0.0.0.0:8000 (1) [2021-10-15 14:20:41 +0000]  [INFO] Using worker: sync [2021-10-15 14:20:41 +0000]  [INFO] Booting worker with pid: 8
How can we retrieve the logs of the previous container?
1 min read
Using the awslogs cli tool we can query groups, streams and events from Amazon CloudWatch logs. It also has a human-friendly format for time-filtering
It's available as using pip so to install it we just need to run:
pip install awslogs