Skip to main content
Glama

k8s_top_pods

Monitor CPU and memory usage for Kubernetes pods to identify resource-intensive containers and optimize cluster performance.

Instructions

Show CPU and memory usage for pods (requires metrics-server)

Input Schema

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

Implementation Reference

  • The `topPods` function implements the `k8s_top_pods` tool logic, fetching CPU and memory usage from the Kubernetes Metrics API.
    export async function topPods(args: Record<string, unknown>): Promise<string> {
      const api = getMetricsApi();
      const namespace = (args.namespace as string) || "default";
    
      const response = await api.listNamespacedCustomObject(
        "metrics.k8s.io",
        "v1beta1",
        namespace,
        "pods"
      );
    
      const body = response.body as { items: MetricsItem[] };
      const items = body.items || [];
    
      if (items.length === 0) {
        return `No metrics available for pods in namespace '${namespace}'. Is metrics-server installed?`;
      }
    
      const headers = ["POD", "CONTAINER", "CPU", "MEMORY"];
      const rows: string[][] = [];
    
      for (const item of items) {
        for (const container of item.containers || []) {
          rows.push([
            item.metadata.name,
            container.name,
            container.usage.cpu,
            container.usage.memory,
          ]);
        }
      }
    
      return `Resource usage for pods in namespace '${namespace}':\n\n${formatTable(headers, rows)}`;
    }
  • Definition of the `k8s_top_pods` tool schema in the Kubernetes tools registry.
    {
      name: "k8s_top_pods",
      description: "Show CPU and memory usage for pods (requires metrics-server)",
      inputSchema: {
        type: "object" as const,
        properties: {
          namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" },
        },
      },
    },
  • Registration of the `k8s_top_pods` tool within the tool dispatcher in `src/tools/kubernetes/index.ts`.
    case "k8s_top_pods": return topPods(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