---
title: Count k8s container restarts
description: Find the Kubernetes container and deployment with the most restarts using `filter` and `top 1 ... by restarts`.
url: https://coralogix.com/docs/dataprime/cookbook/container_restart/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-11-02'
---

# Count k8s container restarts

## 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

```
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

A single log result showing:

```
{

    "container": "server",

    "deployment": "cartservice",

    "restarts": 236

}
```

## TL;DR

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