I am trying to create a system health check. I would like to be able to determine how often the pods are restarting. Since the pods have liveness probes, they may continuously restart if something is wrong. Is there anyway to check the time a pod restarted at instead of just the number of restarts and the total time the pod has been alive?
You can use kubectl get pod -o yaml to view your POD resource in the YAML format (or -o json if you prefer). You can also use kubectl explain pod to list and describe all possible fields associated with the pod API resource.
To see what happened on the pod before it restarted, use kubectl logs your-pod-name --previous . You can pipe this to a file for inspection e.g.
Kubernetes Pods should usually run until they're replaced by a new deployment. As a result, there's no direct way to “restart” a single Pod. If one of your containers experiences an issue, aim to replace it instead of restarting.
To collect or watch the events, you can run kubectl get events --watch in deployment and collect the output with a third-party logging tool. To watch Kubernetes events, many free and paid third-party tools help provide visibility and reporting of events in a Kubernetes cluster resource.
You may want to use a monitoring tool, like cAdvisor/Heapster/Grafana/Prometheus.
Another option you have is to deploy the kube-state-metrics container.
Good articles to read: Monitoring Kubernetes and Get Kubernetes Cluster Metrics with Prometheus. Also, read a similar question on stackoverflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With