k8s.app_status
Check application status in Kubernetes by retrieving pod state information for specified namespace and app label.
Instructions
dada un nombre de aplicacion, busca el estado de los pods
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | Yes | namespace del pod | |
| app | Yes | application label o pod name |
Implementation Reference
- src/index.ts:37-65 (registration)Registration of the 'k8s.app_status' tool, including description, input schema, and handler function that calls getPodInfo and returns JSON results.server.registerTool( "k8s.app_status", { description: "dada un nombre de aplicacion, busca el estado de los pods", inputSchema:z.object( { namespace: z.string().describe("namespace del pod"), app: z.string().describe("application label o pod name"), } ), }, async (args) => { const results = await getPodInfo( args.namespace, args.app ); return { content: [ { type: "text", text: JSON.stringify(results, null, 2), }, ], }; } )
- src/tools/getPodInfo.ts:22-82 (handler)Main handler logic for k8s.app_status: executes kubectl to get pod list by app label/name/namespace and describe each pod, returns PodInfo.export async function getPodInfo( namespace: string, app: string ): Promise<PodInfo> { const result: PodInfo = { namespace, app, podsList: '', podDescriptions: {}, }; try { // 1. Obtener lista de pods // Si 'app' es "*", listar todos los pods // Si 'app' parece ser un nombre completo de pod, usar ese nombre // Si no, buscar por label app=<app> let getPodsCommand: string; if (app === '*' || app === 'all') { // Listar todos los pods del namespace getPodsCommand = `kubectl get pods -n ${namespace} -o wide`; } else if (app.includes('-')) { // Probablemente es un nombre de pod completo getPodsCommand = `kubectl get pods ${app} -n ${namespace} -o wide`; } else { // Buscar por label getPodsCommand = `kubectl get pods -n ${namespace} -l app=${app} -o wide`; } const { stdout: podsListOutput, stderr: getPodsError } = await execAsync(getPodsCommand); if (getPodsError && getPodsError.trim()) { console.warn('Warning getting pods:', getPodsError); } result.podsList = podsListOutput.trim(); // 2. Parsear nombres de pods de la salida (omitir la línea de encabezado) const podLines = podsListOutput.trim().split('\n').slice(1); const podNames = podLines .map(line => line.trim().split(/\s+/)[0]) .filter(name => name && name.length > 0); // 3. Describir cada pod for (const podName of podNames) { try { const describeCommand = `kubectl describe pod ${podName} -n ${namespace}`; const { stdout: describeOutput } = await execAsync(describeCommand); result.podDescriptions[podName] = describeOutput.trim(); } catch (describeError: any) { result.podDescriptions[podName] = `Error describing pod: ${describeError.message}`; } } } catch (error: any) { result.error = `Error executing kubectl commands: ${error.message}`; console.error('Error in getPodInfo:', error); } return result; }
- src/index.ts:41-46 (schema)Input schema for k8s.app_status tool using Zod: requires namespace and app strings.inputSchema:z.object( { namespace: z.string().describe("namespace del pod"), app: z.string().describe("application label o pod name"), } ),
- src/tools/getPodInfo.ts:6-11 (schema)TypeScript interface defining the output structure of getPodInfo (PodInfo).export interface PodInfo { namespace: string; app: string; podsList: string; podDescriptions: { [podName: string]: string }; error?: string;
- src/tools/getPodInfo.ts:1-4 (helper)Helper to promisify child_process.exec for async kubectl command execution.import { exec } from 'child_process'; import { promisify } from 'util'; const execAsync = promisify(exec);