Skip to main content
Glama

k8s_describe_pod

Retrieve detailed Kubernetes pod information including containers, resources, and events to diagnose issues and monitor pod status.

Instructions

Get detailed information about a specific pod including containers, resources, and events

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesPod name
namespaceNoKubernetes namespace (default: 'default')

Implementation Reference

  • Handler function for `k8s_describe_pod` that fetches pod details from the Kubernetes API and formats them.
    export async function describePod(args: Record<string, unknown>): Promise<string> {
      const api = getCoreV1Api();
      const namespace = (args.namespace as string) || "default";
      const name = args.name as string;
    
      if (!name) throw new Error("Pod name is required");
    
      const response = await api.readNamespacedPod(name, namespace);
      const pod = response.body;
    
      const lines: string[] = [
        `Name:         ${pod.metadata?.name}`,
        `Namespace:    ${pod.metadata?.namespace}`,
        `Node:         ${pod.spec?.nodeName || "N/A"}`,
        `Status:       ${pod.status?.phase}`,
        `IP:           ${pod.status?.podIP || "N/A"}`,
        `Labels:       ${pod.metadata?.labels ? Object.entries(pod.metadata.labels).map(([k, v]) => `${k}=${v}`).join(", ") : "none"}`,
        "",
        "Containers:",
      ];
    
      for (const container of pod.spec?.containers || []) {
        const status = pod.status?.containerStatuses?.find((s) => s.name === container.name);
        lines.push(`  ${container.name}:`);
        lines.push(`    Image:    ${container.image}`);
        lines.push(`    Ready:    ${status?.ready ?? "unknown"}`);
        lines.push(`    Restarts: ${status?.restartCount ?? 0}`);
    
        if (container.resources?.limits) {
          lines.push(`    Limits:   CPU=${container.resources.limits.cpu || "none"}, Mem=${container.resources.limits.memory || "none"}`);
        }
        if (container.resources?.requests) {
          lines.push(`    Requests: CPU=${container.resources.requests.cpu || "none"}, Mem=${container.resources.requests.memory || "none"}`);
        }
      }
    
      // Events
      const events = await api.listNamespacedEvent(
        namespace,
        undefined,
        undefined,
        undefined,
        `involvedObject.name=${name}`
      );
    
      if (events.body.items.length > 0) {
        lines.push("", "Events:");
        const eventHeaders = ["TYPE", "REASON", "AGE", "MESSAGE"];
        const eventRows = events.body.items
          .sort((a, b) => {
            const aTime = a.lastTimestamp || a.metadata?.creationTimestamp;
            const bTime = b.lastTimestamp || b.metadata?.creationTimestamp;
            return new Date(bTime || 0).getTime() - new Date(aTime || 0).getTime();
          })
          .slice(0, 10)
          .map((e) => [
            e.type || "Normal",
            e.reason || "",
            e.lastTimestamp ? formatAge(e.lastTimestamp) : "?",
            e.message || "",
          ]);
        lines.push(formatTable(eventHeaders, eventRows));
      }
    
      return lines.join("\n");
    }
  • Registration of `k8s_describe_pod` tool with its schema definition.
    {
      name: "k8s_describe_pod",
      description: "Get detailed information about a specific pod including containers, resources, and events",
      inputSchema: {
        type: "object" as const,
        properties: {
          name: { type: "string", description: "Pod name" },
          namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" },
        },
        required: ["name"],
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/batu-sonmez/infraclaude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server