# Count k8s container restarts

Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Fcookbook%2Fcontainer_restart.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Fcookbook%2Fcontainer_restart.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

## Problem / Use case[​](#problem--use-case "Direct link to Problem / Use case")

You want to identify the Kubernetes container with the highest number of restarts across your logs. This helps prioritize investigation into unstable or crashing deployments.

## Query[​](#query "Direct link to Query")

```
source logs

| choose resource.attributes.k8s_container_restart_count:number as restarts, 

         resource.attributes.k8s_container_name as container, 

         resource.attributes.k8s_deployment_name as deployment

| filter restarts > 0

| top 1 container, deployment by restarts
```

## Expected output[​](#expected-output "Direct link to Expected output")

A single log result showing:

```
{

    "container": "server",

    "deployment": "cartservice",

    "restarts": 236

}
```

## TL;DR[​](#tldr "Direct link to TL;DR")

Pinpoint the most restart-prone container with `top 1 ... by restarts`. Helps surface high-impact instability fast.
