Skip to main content
Glama

k8s_get_pods

Retrieve and monitor Kubernetes pods by listing their status, restart counts, and age. Filter results using namespace, label selectors, or field selectors to manage container workloads.

Instructions

List pods in a Kubernetes namespace with their status, restarts, and age

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNoKubernetes namespace (default: 'default')
label_selectorNoLabel selector to filter pods (e.g., 'app=nginx')
field_selectorNoField selector (e.g., 'status.phase=Running')

Implementation Reference

  • The actual logic that calls the Kubernetes API to get pods.
    export async function getPods(args: Record<string, unknown>): Promise<string> {
      const api = getCoreV1Api();
      const namespace = (args.namespace as string) || "default";
      const labelSelector = args.label_selector as string | undefined;
      const fieldSelector = args.field_selector as string | undefined;
    
      const response = await api.listNamespacedPod(
        namespace,
        undefined,
        undefined,
        undefined,
        fieldSelector,
        labelSelector
      );
    
      const pods = response.body.items;
      if (pods.length === 0) {
        return `No pods found in namespace '${namespace}'${labelSelector ? ` with selector '${labelSelector}'` : ""}.`;
      }
    
      const headers = ["NAME", "READY", "STATUS", "RESTARTS", "AGE"];
      const rows = pods.map((pod) => {
        const containers = pod.status?.containerStatuses || [];
        const ready = containers.filter((c) => c.ready).length;
        const total = containers.length || pod.spec?.containers.length || 0;
        const restarts = containers.reduce((sum, c) => sum + (c.restartCount || 0), 0);
        const status = pod.status?.phase || "Unknown";
        const age = pod.metadata?.creationTimestamp
          ? formatAge(pod.metadata.creationTimestamp)
          : "?";
    
        return [
          pod.metadata?.name || "unknown",
          `${ready}/${total}`,
          status,
          String(restarts),
          age,
        ];
      });
    
      return `Pods in namespace '${namespace}':\n\n${formatTable(headers, rows)}`;
    }
  • The tool definition (schema) for k8s_get_pods.
    {
      name: "k8s_get_pods",
      description: "List pods in a Kubernetes namespace with their status, restarts, and age",
      inputSchema: {
        type: "object" as const,
        properties: {
          namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" },
          label_selector: { type: "string", description: "Label selector to filter pods (e.g., 'app=nginx')" },
          field_selector: { type: "string", description: "Field selector (e.g., 'status.phase=Running')" },
        },
      },
    },
  • The dispatcher logic inside handleKubernetesTool that routes the request to the getPods function.
    case "k8s_get_pods": return getPods(a);

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