k8s_get_deployments
Retrieve Kubernetes deployment details including replica status, strategy, and age for infrastructure management and monitoring.
Instructions
List deployments with replica status, strategy, and age
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | Kubernetes namespace (default: 'default') | |
| label_selector | No | Label selector to filter |
Implementation Reference
- src/tools/kubernetes/deployments.ts:4-45 (handler)The `getDeployments` function, which fetches and formats Kubernetes deployments from a given namespace.
export async function getDeployments(args: Record<string, unknown>): Promise<string> { const api = getAppsV1Api(); const namespace = (args.namespace as string) || "default"; const labelSelector = args.label_selector as string | undefined; const response = await api.listNamespacedDeployment( namespace, undefined, undefined, undefined, undefined, labelSelector ); const deployments = response.body.items; if (deployments.length === 0) { return `No deployments found in namespace '${namespace}'.`; } const headers = ["NAME", "READY", "UP-TO-DATE", "AVAILABLE", "AGE", "STRATEGY"]; const rows = deployments.map((dep) => { const ready = dep.status?.readyReplicas || 0; const desired = dep.spec?.replicas || 0; const upToDate = dep.status?.updatedReplicas || 0; const available = dep.status?.availableReplicas || 0; const age = dep.metadata?.creationTimestamp ? formatAge(dep.metadata.creationTimestamp) : "?"; const strategy = dep.spec?.strategy?.type || "RollingUpdate"; return [ dep.metadata?.name || "unknown", `${ready}/${desired}`, String(upToDate), String(available), age, strategy, ]; }); return `Deployments in namespace '${namespace}':\n\n${formatTable(headers, rows)}`; } - src/tools/kubernetes/index.ts:203-203 (registration)The registration point in the switch statement for the `k8s_get_deployments` tool.
case "k8s_get_deployments": return getDeployments(a);