# Summarize container restarts by deployment

## Problem / Use case

You want to track Kubernetes container stability by calculating restart counts per deployment. This helps spot unhealthy pods or unstable deployments using percentiles and max values.

## Query

```dataprime
source logs
| choose resource.attributes.k8s_container_restart_count as restarts, 
    resource.attributes.k8s_deployment_name as deployment
| filter restarts > 0
| groupby deployment agg
    round(percentile(0.5, restarts), 2) as p50_restarts,
    round(percentile(0.9, restarts), 2) as p90_restarts,
    round(max(restarts), 0) as max_restarts
| orderby max_restarts desc
```

Note

remember that certain fields like `resource.attributes.k8s_container_restart_count` may require to be casted into a `number` type

## Expected output

A sorted table showing deployments with the highest container restart counts:

| deployment            | p50_restarts | p90_restarts | max_restarts |
| --------------------- | ------------ | ------------ | ------------ |
| cartservice           | 231.9        | 233          | 235          |
| recommendationservice | 32           | 32.52        | 33           |
| loadgenerator         | 24           | 24           | 25           |
| k8s-watcher           | 4            | 5            | 5            |
| otelcollector         | 4            | 4            | 4            |
| emailservice          | 4            | 4            | 4            |
