{"data":{"slug":"github-google-skills-skills-cloud-gke-workload-troubleshooting-47e08566c885","title":"GKE Workload Troubleshooting","summary":"Diagnose GKE workload failures like CrashLoopBackOff, OOMKilled, and ImagePullBackOff using logs and events. Proposes fixes without executing live mutations.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-troubleshooting-47e08566c885","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-gke-workload-troubleshooting-47e08566c885","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-troubleshooting-47e08566c885.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-troubleshooting-47e08566c885\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you MUST read [Usage Attribution](references\/attribution.md). For terminal commands, prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-workload-troubleshooting)\"` and append `agent-skills\/1.0 (skill:gke-workload-troubleshooting)` to `User-Agent` headers.","instructions":"---\nname: gke-workload-troubleshooting\nmetadata:\n  version: \"1.0.1\"\n  category: Containers\ndescription: >-\n  Diagnoses GKE workload failures (CrashLoopBackOff, OOMKilled, ImagePullBackOff, Pending, etc.) via logs and events. Use when pods fail to start or crash repeatedly. Don't use for GKE cluster infrastructure provisioning, node pool creation, or non-Kubernetes Google Cloud services.\n---\n\n# GKE Workload Troubleshooting Skill\n\nUse this skill to systematically diagnose and resolve failures in application\nworkloads deployed in GKE clusters. This skill operates non-interactively and\nenforces a read-only diagnostics boundary: it only **proposes** fixes \u2014 whether\nKubernetes manifest\/config patches or Google Cloud changes (for example `gcloud`\nIAM bindings or node-pool recreation) \u2014 and never executes live mutations\nitself.\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-workload-troubleshooting)\"`\nand append `agent-skills\/1.0 (skill:gke-workload-troubleshooting)` to `User-Agent` headers.\n\n## \ud83d\udd0d Diagnostic Workflow\n\n### Step 0: Non-Interactive Context Discovery & Time Window Definition\n\n1.  **Parameter Extraction**: Extract required context (`project_id`,\n    `cluster_name`, `cluster_location`, `workload_name`, `workload_namespace`)\n    non-interactively from the user prompt, active `SETTINGS.md`, or active\n    environment defaults:\n\n    -   Default `workload_namespace` to `default` if omitted.\n    -   Infer missing cluster parameters from active environment (`kubectl\n        config current-context` or `gcloud config get-value project`).\n    -   Prioritize non-interactive context discovery from prompts and\n        environment defaults to ensure autonomous execution flow.\n\n2.  **Cluster Credentials & Fallback Mode**:\n\n    -   Attempt credential fetch: `gcloud container clusters get-credentials\n        {cluster_name} --region\/--zone {cluster_location}`\n    -   **Fallback \/ Dry-Run Mode**: If the cluster is unreachable,\n        non-existent, or live command execution fails (such as in sandboxed\n        evaluations, dry-run mode, or offline analysis):\n        -   Limit retry attempts to avoid resource exhaustion and context\n            overflow in unreachable cluster scenarios.\n        -   Immediately present the exact sequence of `kubectl` diagnostic\n            commands for the human operator to run.\n        -   Synthesize the root cause analysis and output the proposed GitOps\n            manifest fix based on the reported symptoms.\n\n3.  **Time Handling & Fallbacks**:\n\n    -   **Determine Issue Timestamp ({issue_time})**:\n        -   **Specific Time Provided**: If the user provides a specific\n            timestamp, use it as `{issue_time}`.\n        -   **Relative Time Provided (e.g., \"5 minutes ago\")**: Dynamically\n            calculate the corresponding UTC timestamp based on current system\n            time, and use it as `{issue_time}`.\n        -   **No Time Provided (Default)**: Use current system time as\n            `{issue_time}`.\n    -   **Window Calculation**: Center a 1-hour query window around\n        `{issue_time}` (`start_time` = `{issue_time} - 30m`, `end_time` =\n        `{issue_time} + 30m`).\n\n--------------------------------------------------------------------------------\n\n### Step 1: Analyze Pod Status and Conditions\n\nInspect the workload's active pod states and controller status.\n\n**Diagnostic Commands:**\n\n```bash\n# 1. Inspect the deployment's actual selector labels:\nkubectl get deployment {workload_name} -n {workload_namespace} -o jsonpath='{.spec.selector.matchLabels}'\n# 2. Query the pods using the returned labels, for example:\nkubectl get pods -l {selector_labels} -n {workload_namespace}\nkubectl get deploy\/{workload_name} -n {workload_namespace} -o yaml\n```\n\n#### Diagnostic Decision Tree:\n\n-   **Phase: Pending**:\n    -   The Pod cannot schedule on any node. Proceed directly to **Step 2 (Query\n        Namespace Events)**.\n-   **State: CrashLoopBackOff \/ Error**:\n\n    -   The container boots but exits repeatedly; the `kubelet` restarts it with\n        an increasing back-off delay of up to five minutes. First read the\n        terminated **reason** and **exit code**:\n\n    ```bash\n    kubectl describe pod {pod_name} -n {workload_namespace}\n    kubectl get pod {pod_name} -n {workload_namespace} -o jsonpath='{.status.containerStatuses[*].lastState.terminated}'\n    ```\n\n    -   **Reason: OOMKilled (Exit Code 137)**: The container's memory limit was\n        reached. Proceed to **Step 3 (Inspect Logs) \u2192 OOM Analysis** to classify\n        container-level vs node-level, then **Step 5** to propose fixes.\n    -   **Exit Code 0 (successful exit)**: Unexpected for a long-running\n        Deployment\/StatefulSet \u2014 `restartPolicy: Always` restarts the finished\n        process, creating the loop. Common causes: the `command`\/`entrypoint`\n        does not start a persistent process, a worker exits on an empty queue,\n        or a missing\/invalid config (e.g., an unattached or mis-keyed\n        `ConfigMap` volume) makes the app exit cleanly. Proceed to **Step 3\n        (Inspect Logs)**.\n    -   **Exit Code 128**: Invalid `command`\/`entrypoint` \u2014 the executable path\n        is wrong or absent in the image. Verify the container command in the\n        manifest.\n    -   **Exit Code 1 or other non-zero**: The application crashed \u2014\n        configuration errors, missing\/invalid env vars or config files,\n        unreachable dependencies, or auth failures (`401`\/`403`) on Google Cloud\n        calls (check the Pod's IAM \/ Workload Identity Federation). Proceed\n        directly to **Step 3 (Inspect Logs)**.\n    -   If the exit code looks healthy but the container keeps restarting,\n        suspect a **liveness probe failure** (see Step 3).\n\n-   **State: ImagePullBackOff \/ ErrImagePull**:\n\n    -   The kubelet cannot pull the container image. `ImagePullBackOff` means it\n        keeps retrying with back-off; `ErrImagePull` is a general,\n        non-recoverable pull error. Related statuses: `InvalidImageName`,\n        `RegistryUnavailable`, `SignatureValidationFailed`, `ImageInspectError`.\n        Proceed to **Step 2 (Query Namespace Events)** to read the exact pull\n        error message.\n\n-   **State: ContainerCreating**:\n\n    -   The container is blocked during volume mount, networking setup, or image\n        pulling. Proceed directly to **Step 2 (Query Namespace Events)**.\n\n--------------------------------------------------------------------------------\n\n### Step 2: Query Namespace Events\n\nLook for infrastructure, volume, image, or scheduling alerts in GKE.\n\n**Diagnostic Command:**\n\n```bash\nkubectl get events -n {workload_namespace} --sort-by='.metadata.creationTimestamp'\n# Or query Cloud Logging for historical GKE events within the time window:\ngcloud logging read \"resource.type=\\\"k8s_cluster\\\" AND logName=\\\"projects\/{project_id}\/logs\/events\\\" AND jsonPayload.involvedObject.namespace=\\\"{workload_namespace}\\\"\" --start-time=\"{start_time}\" --end-time=\"{end_time}\" --project=\"{project_id}\"\n# Or query specifically for image pull failures within the time window:\ngcloud logging read 'log_id(\"events\") AND resource.type=\"k8s_pod\" AND resource.labels.cluster_name=\"{cluster_name}\" AND jsonPayload.message=~\"Failed to pull image\"' --project=\"{project_id}\"\n```\n\n*Note: Retrieve the sorted events list and manually inspect the event timestamps\n(CreationTimestamp\/LastSeen) to identify failures occurring within the\n`{start_time}` and `{end_time}` window.*\n\n#### Signature Identifiers:\n\n-   **`FailedScheduling`**: Node resource exhaustion. Look for messages like\n    `0\/3 nodes are available: 3 Insufficient memory.` or missing node affinity\n    tolerations (e.g. Spot VM taints).\n-   **`FailedMount`**:\n    -   Missing PersistentVolumeClaim (`PVC`).\n    -   Missing Secret (`Secret \"{secret_name}\" not found`).\n    -   Missing ConfigMap (`ConfigMap \"{configmap_name}\" not found`).\n-   **`Failed` \/ `BackOff` (Image Pull)**: First read the exact event message\n    (`Failed to pull image \"IMAGE\": ...`) and triage by what it actually says.\n    Do **not** jump to IAM \/ node service-account investigation unless the\n    message is genuinely a permission or authentication error.\n\n    -   **Wrong image name\/tag \u2014 start here** (`not found`, `manifest unknown`,\n        `InvalidImageName`): the most common cause \u2014 the tag or path is wrong,\n        or the image was deleted, frequently introduced by a recent deployment\n        change.\n        *   Identify the failing container image name and the invalid tag.\n        *   Check the Git history for the last known working image tag: `git log\n            -p -S \"{image_name}\" -- {manifest_file_path}` (or run `git log` on\n            the folder containing manifests).\n        *   Propose reverting the image tag to the last working version (or\n            correcting the tag) in the manifest patch.\n    -   **Permission \/ authentication errors only** (the message contains `403\n        Forbidden` \/ `denied`, or `401 Unauthorized` \/ `unauthorized`): the node\n        cannot authorize or authenticate to the registry. Pursue the checks\n        below **only** when the message matches.\n\n        *   **`403 Forbidden` (authorization)** \u2014 the node pool service account\n            (or the imagePullSecret's service account) is missing registry read\n            access. **Suggest** granting it by presenting the following command\n            for the user to review and run; do not execute it. For **Artifact\n            Registry**:\n\n            ```bash\n            gcloud artifacts repositories add-iam-policy-binding {repository} \\\n              --location={repo_location} \\\n              --member=\"serviceAccount:{node_service_account_email}\" \\\n              --role=\"roles\/artifactregistry.reader\"\n            ```\n\n            For **Container Registry (`gcr.io`)**, grant\n            `roles\/storage.objectViewer` on the backing bucket (or the Artifact\n            Registry role if `gcr.io` was migrated). Also check that any **VPC\n            Service Controls** perimeter allows Artifact Registry.\n        *   **`401 Unauthorized` (authentication)** \u2014 the node service account\n            is disabled or the node lacks the required OAuth scope:\n\n            ```bash\n            gcloud container clusters describe {cluster_name} --location={cluster_location} \\\n              --format=\"table(nodePools.name,nodePools.config.serviceAccount)\"\n            gcloud iam service-accounts list \\\n              --filter=\"email:{node_service_account_email} AND disabled:true\" --project={project_id}\n            gcloud compute instances describe {node_name} --zone={node_zone} \\\n              --format=\"flattened(serviceAccounts[].scopes)\"\n            ```\n\n            Scopes must include `devstorage.read_only` or `cloud-platform`\n            (provided by `gke-default`). Nodes are immutable, so **suggest**\n            recreating the node pool with `--scopes=\"gke-default\"` if the scope\n            is missing \u2014 present it as a proposed command for the user to run,\n            do not execute it.\n        *   **Private \/ self-hosted registry**: ensure a valid `imagePullSecret`\n            exists and is referenced by the Deployment.\n    -   **Other statuses**: `RegistryUnavailable` \/ `i\/o timeout` \/ DNS `server\n        misbehaving` \u2192 registry network path (DNS, firewall egress, Google API\n        connectivity); `exec format error` or a deprecated schema-1 image \u2192\n        architecture\/schema mismatch.\n\n--------------------------------------------------------------------------------\n\n### Step 3: Inspect Application Logs\n\nExtract exceptions and stack traces from the application runtime.\n\n**Diagnostic Commands:**\n\n```bash\n# Check current active log stream (handles multi-container pods)\nkubectl logs {pod_name} -n {workload_namespace} --all-containers --tail=100\n\n# Check logs from previously terminated container instances (handles multi-container pods)\nkubectl logs {pod_name} -n {workload_namespace} --all-containers -p --tail=100\n```\n\n#### Signature Identifiers:\n\n-   **Out-of-Memory (OOM) Analysis**: First confirm and classify the kill.\n\n    -   **Container-level OOM** (most common): `kubectl describe pod` shows\n        `Last State: Terminated`, `Reason: OOMKilled`, `Exit Code: 137`. The\n        container exceeded its cgroup memory limit. Differentiate an\n        **application memory leak\/loop** (unbounded growth in logs and startup\n        command) from an **infrastructure capacity mismatch** (legitimate demand\n        exceeding `resources.limits.memory`).\n    -   **Node-level (system) OOM**: the entire node ran out of memory; look for\n        evicted Pods and node-pressure eviction. The combined memory of all Pods\n        exceeded node capacity.\n    -   **\"Invisible\" OOM** (`cgroup v1`): a child process is killed but the\n        main process (PID 1) keeps running, so Kubernetes never marks\n        `OOMKilled`. Search node logs in Cloud Logging:\n\n        ```bash\n        gcloud logging read 'resource.type=\"k8s_node\" AND resource.labels.cluster_name=\"{cluster_name}\" AND jsonPayload.MESSAGE:(\"TaskOOM event\" OR \"ContainerDied\")' --project=\"{project_id}\"\n        ```\n\n        A `TaskOOM` entry confirms an OOM kill; match its container ID to the\n        `ContainerDied` entry to find the affected Pod. On the node, `journalctl\n        -k` distinguishes container-level kills (`memory cgroup`, `memcg`) from\n        system-level kills (`Out of memory: Killed process`).\n    -   Do not rely solely on sampled memory metrics \u2014 they often miss the spike\n        that triggers the kill. Then proceed to **Step 5** to propose fixes\n        (raise limits, fix the leak, or right-size the node pool).\n-   **Liveness Probe Failure (CrashLoop with no application error)**: if the\n    container restarts but its logs show no crash, the `kubelet` may be killing\n    it on failed liveness probes (default `failureThreshold: 3`). Confirm in\n    Cloud Logging:\n\n    ```bash\n    gcloud logging read 'resource.type=\"k8s_node\" AND log_id(\"kubelet\") AND jsonPayload.MESSAGE:\"failed liveness probe, will be restarted\" AND resource.labels.cluster_name=\"{cluster_name}\"' --project=\"{project_id}\"\n    ```\n\n    Common fixes: correct the probe type\/path\/port, raise `initialDelaySeconds`\n    or `timeoutSeconds`\/`failureThreshold` for slow starts, or relieve CPU\/disk\n    I\/O contention causing probe timeouts. Keep probe commands lightweight.\n-   **Stack Trace \/ Unhandled Exception**: Look for language-specific stack\n    traces (e.g., `panic:`, `NullPointerException`, `Traceback (most recent\n    call)`). This indicates an application bug.\n-   **Egress Network Timeout**: Look for connection timeouts (e.g., `Connection\n    timed out`, `dial tcp: i\/o timeout`). Proceed to **Step 4 (Verify\n    Connectivity)**.\n-   **Permission Errors (ReadOnlyRootFilesystem)**: Look for write errors (e.g.,\n    `Read-only file system`, `Permission denied` when writing to `\/tmp` or\n    `\/var\/log`). Propose adding an `emptyDir` volume mount to that directory in\n    the manifest.\n\n--------------------------------------------------------------------------------\n\n### Step 4: Verify Service Connectivity and Network Policies\n\nTroubleshoot connection drops to other services.\n\n**Diagnostic Commands:**\n\n```bash\n# Verify target endpoint is active\nkubectl get endpoints {target_service_name} -n {target_namespace}\n\n# Query network policies inside namespace\nkubectl get networkpolicies -n {workload_namespace} -o yaml\n```\n\n#### Logic & Dry-Run Fallback:\n\n1.  **Live Cluster Mode**:\n\n    -   If `kubectl get endpoints` returns an empty list, the target\n        microservice itself is failing to schedule or boot (troubleshoot target\n        service).\n    -   If endpoints exist but logs show timeouts, analyze `NetworkPolicy`\n        egress blocks to verify if egress traffic to the target service's\n        IP\/port is allowed.\n\n2.  **Sandboxed \/ Dry-Run Mode**:\n\n    -   If live `kubectl` queries fail or cluster connection is unavailable, do\n        NOT retry live cluster access or enter repetitive connection attempts.\n    -   Immediately inspect the application source code (e.g. `worker.py`,\n        `app.go`, DB connection strings) or Deployment manifests to identify the\n        target service hostname (e.g. `account-db`) and destination port (e.g.\n        `5432`).\n    -   Present the exact `kubectl get endpoints` and `kubectl get\n        networkpolicies` commands for the user, and synthesize the required\n        `NetworkPolicy` egress patch allowing traffic to the target service and\n        port.\n\n--------------------------------------------------------------------------------\n\n### Step 5: Propose GitOps Correction\n\nFollowing the GitOps boundary, **do not apply changes directly** \u2014 this includes\nboth cluster manifest\/config patches and any Google Cloud mutations (for example\n`gcloud` IAM bindings or node-pool recreation). Present every change as a\nreviewable suggestion: a manifest patch \/ PR, or a command for the user to run.\n\n1.  Synthesize the root cause analysis for the human operator (e.g.\n    *\"payment-api is failing with exit code 137 because its memory limit is set\n    to 256Mi while actual usage spiked to 270Mi\"*).\n2.  Generate the corrected YAML manifest patch (e.g. increase memory limits, add\n    missing Secret mounts, or add tolerations for Spot nodes).\n3.  Check if a branch or Pull Request (PR) already exists for this\n    workload\/failure. If so, update the existing branch\/PR or notify the user\n    instead of creating a duplicate. Otherwise, create a branch, commit the\n    change, open a Pull Request (PR) on GitHub, and conclude the workflow (do\n    not wait for human merge).\n\n--------------------------------------------------------------------------------\n\n## References\n\n-   [Troubleshoot OOM events](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/troubleshooting\/oom-events.md.txt)\n-   [Troubleshoot image pulls](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/troubleshooting\/image-pulls.md.txt)\n-   [Troubleshoot CrashLoopBackOff events](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/troubleshooting\/crashloopbackoff-events.md.txt)\n-   [Troubleshoot deployed workloads](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/troubleshooting\/deployed-workloads.md.txt)\n-   [Artifact Registry access control with GKE](https:\/\/docs.cloud.google.com\/artifact-registry\/docs\/access-control.md.txt#gke)\n","use_cases":["Diagnose CrashLoopBackOff errors in GKE deployments","Investigate OOMKilled issues in Kubernetes pods","Resolve ImagePullBackOff errors in containerized applications"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/gke-workload-troubleshooting\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T17:02:04.000000Z","updated_at":"2026-11-17T10:20:00.000000Z","seo_title":"GKE Workload Troubleshooting: Fix CrashLoopBackOff and OOMKilled","seo_description":"Diagnose GKE workload failures with logs and events. Fix CrashLoopBackOff, OOMKilled, and ImagePullBackOff issues efficiently.","seo_keywords":["GKE workload troubleshooting","CrashLoopBackOff diagnosis","OOMKilled resolution","ImagePullBackOff fix","Kubernetes pod debugging"]}}