Skip to main content
Kubernetes pods stuck in crash loops are among the most urgent production issues you’ll face as an SRE. When a pod continuously fails to start, restarting every few seconds or minutes, it can take down critical services and leave users unable to access your application. The crash loop might be caused by application bugs, missing dependencies, resource constraints, configuration errors, or connectivity issues to external services. Every crash loop investigation follows the same tedious pattern: checking pod status and events, reviewing container logs from current and previous restarts, examining resource usage to identify OOM kills, verifying configuration and secrets, and testing connectivity to dependencies. You’re frantically switching between kubectl commands while production is down and users are impacted.

Example Alert

Here is an example Kubernetes crash loop alert our Agent will investigate:

Creating A Kubernetes Crash Loop Investigation Agent

Let’s create an Agent that runs every time we get a pod crash loop alert. Our Agent will extract the pod and namespace from the alert, analyze the pod’s status and events, examine container logs from current and previous restarts, check resource usage for OOM kills, verify configuration dependencies, and test connectivity to external services. After installing Unpage, create the agent by running:
A yaml file will open in your $EDITOR. Paste the following Agent definition into the file:
Let’s dig in to what each section of the yaml file does:

Description: When the agent should run

The description of an Agent is used by the Router to decide which Agent to run for a given input. In this example we want the Agent to run only when the alert is about Kubernetes pod crash loops or CrashLoopBackOff.

Prompt: What the agent should do

The prompt is where you give the Agent instructions, written in a runbook format. Make sure any instructions you give are achievable using the tools you have allowed the Agent to use (see below).

Tools: What the agent is allowed to use

The tools section explicitly grants permission to use specific tools. You can list individual tools, or use wildcards and regex patterns to limit what the Agent can use. To see all of the available tools your Unpage installation has access to, run:
In our example we added several custom kubectl commands for Kubernetes diagnostics:
  • shell_kubectl_get_pod
  • shell_kubectl_describe_pod
  • shell_kubectl_logs_current
  • shell_kubectl_logs_previous
  • shell_kubectl_get_events
  • shell_kubectl_top_pod
  • shell_kubectl_get_configmaps
  • shell_kubectl_get_secrets
These are custom shell commands that use kubectl to diagnose pod crash loops. Custom shell commands allow you to extend the functionality of Unpage without having to write a new plugin.

Defining Custom Tools

To add our custom Kubernetes analysis tools, edit ~/.unpage/profiles/default/config.yaml and add the following:
Shell commands have full access to your environment and can run kubectl commands against your Kubernetes clusters. Make sure your kubectl context is configured correctly and you have appropriate RBAC permissions. See shell commands for more details.

Running Your Agent

With your Agent configured and the custom Kubernetes analysis tools added, we are ready to test it on a real PagerDuty alert.

Testing on an existing alert

To test your Agent locally on a specific PagerDuty alert, run:

Listening for webhooks

To have your Agent listen for new PagerDuty alerts as they happen, run unpage agent serve and add the webhook URL to your PagerDuty account:

Example Output

Your Agent will update the alert with:
  • Current pod status, restart count, and crash frequency analysis
  • Container exit codes and termination reasons from recent restarts
  • Critical error messages and stack traces from current and previous logs
  • Kubernetes events showing scheduling, pulling, or startup failures
  • Resource usage patterns indicating OOM kills or CPU throttling
  • Verification of ConfigMaps, Secrets, and other configuration dependencies
  • External service connectivity test results
  • Root cause analysis with specific remediation recommendations
The Agent transforms a frantic crash loop investigation into a structured analysis, providing the exact information needed to quickly identify whether the issue is application code, resource constraints, configuration problems, or infrastructure, enabling faster resolution and reduced downtime.