k8s_get_services
Retrieve Kubernetes service details including type, cluster IP, ports, and age to monitor and manage network configurations in your cluster.
Instructions
List services with type, cluster IP, ports, and age
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | Kubernetes namespace (default: 'default') |
Implementation Reference
- src/tools/kubernetes/services.ts:4-32 (handler)The actual implementation of the 'k8s_get_services' tool logic. It interacts with the K8s CoreV1 API to list services in a given namespace and formats them into a table.
export async function getServices(args: Record<string, unknown>): Promise<string> { const api = getCoreV1Api(); const namespace = (args.namespace as string) || "default"; const response = await api.listNamespacedService(namespace); const services = response.body.items; if (services.length === 0) { return `No services found in namespace '${namespace}'.`; } const headers = ["NAME", "TYPE", "CLUSTER-IP", "EXTERNAL-IP", "PORTS", "AGE"]; const rows = services.map((svc) => { const ports = (svc.spec?.ports || []) .map((p) => `${p.port}${p.nodePort ? `:${p.nodePort}` : ""}/${p.protocol || "TCP"}`) .join(", "); return [ svc.metadata?.name || "unknown", svc.spec?.type || "ClusterIP", svc.spec?.clusterIP || "None", svc.status?.loadBalancer?.ingress?.[0]?.ip || "<none>", ports, svc.metadata?.creationTimestamp ? formatAge(svc.metadata.creationTimestamp) : "?", ]; }); return `Services in namespace '${namespace}':\n\n${formatTable(headers, rows)}`; } - src/tools/kubernetes/index.ts:140-148 (registration)Registration and schema definition for the 'k8s_get_services' tool.
name: "k8s_get_services", description: "List services with type, cluster IP, ports, and age", inputSchema: { type: "object" as const, properties: { namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" }, }, }, }, - src/tools/kubernetes/index.ts:207-207 (handler)Router in 'handleKubernetesTool' that dispatches the request to the 'getServices' handler function.
case "k8s_get_services": return getServices(a);