Skip to main content
Glama

k8s_get_pod_logs

Fetch Kubernetes pod logs with options for tail lines, time range, and container selection to troubleshoot and monitor application performance.

Instructions

Fetch logs from a pod with options for tail lines, time range, and container selection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesPod name
namespaceNoKubernetes namespace (default: 'default')
containerNoContainer name (for multi-container pods)
tailNoNumber of lines from the end (default: 100)
sinceNoTime duration (e.g., '5m', '1h', '2d')
previousNoGet logs from previous container instance

Implementation Reference

  • The actual implementation of the tool that interacts with the Kubernetes API to fetch pod logs.
    export async function getPodLogs(args: Record<string, unknown>): Promise<string> {
      const api = getCoreV1Api();
      const namespace = (args.namespace as string) || "default";
      const name = args.name as string;
      const container = args.container as string | undefined;
      const tail = (args.tail as number) || 100;
      const since = args.since as string | undefined;
      const previous = (args.previous as boolean) || false;
    
      if (!name) throw new Error("Pod name is required");
    
      let sinceSeconds: number | undefined;
      if (since) {
        const match = since.match(/^(\d+)([smhd])$/);
        if (match) {
          const value = parseInt(match[1]);
          const unit = match[2];
          const multipliers: Record<string, number> = { s: 1, m: 60, h: 3600, d: 86400 };
          sinceSeconds = value * (multipliers[unit] || 1);
        }
      }
    
      const response = await api.readNamespacedPodLog(
        name,
        namespace,
        container,
        undefined,
        undefined,
        undefined,
        undefined,
        previous,
        sinceSeconds,
        tail
      );
    
      const logs = response.body;
      if (!logs || logs.trim().length === 0) {
        return `No logs found for pod '${name}'${container ? ` container '${container}'` : ""} in namespace '${namespace}'.`;
      }
    
      const header = `Logs for pod '${name}'${container ? ` (container: ${container})` : ""} in '${namespace}' (last ${tail} lines):`;
      return `${header}\n\n${logs}`;
    }
  • Schema definition for k8s_get_pod_logs.
      name: "k8s_get_pod_logs",
      description: "Fetch logs from a pod with options for tail lines, time range, and container selection",
      inputSchema: {
        type: "object" as const,
        properties: {
          name: { type: "string", description: "Pod name" },
          namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" },
          container: { type: "string", description: "Container name (for multi-container pods)" },
          tail: { type: "number", description: "Number of lines from the end (default: 100)" },
          since: { type: "string", description: "Time duration (e.g., '5m', '1h', '2d')" },
          previous: { type: "boolean", description: "Get logs from previous container instance" },
        },
        required: ["name"],
      },
    },
  • Tool registration/routing for k8s_get_pod_logs.
    case "k8s_get_pod_logs": return getPodLogs(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