pod_logs
Retrieve logs from a Kubernetes pod or specific container within it, supporting optional parameters like tail lines and previous instance logs, simplifying debugging and monitoring tasks.
Instructions
Get logs from a pod or a specific container within the pod.
Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The pod name container: Optional container name (if pod has multiple containers) tail_lines: Number of lines to retrieve from the end of the logs previous: Whether to get logs from a previous instance of the container
Returns: Pod logs
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container | No | ||
| context_name | Yes | ||
| name | Yes | ||
| namespace | Yes | ||
| previous | No | ||
| tail_lines | No |
Implementation Reference
- tools/pod.py:334-368 (handler)The handler function for the 'pod_logs' tool. It retrieves logs from a specified Kubernetes pod (and optional container) using the Kubernetes CoreV1Api client. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() @use_current_context def pod_logs(context_name: str, namespace: str, name: str, container: str = None, tail_lines: int = 100, previous: bool = False): """ Get logs from a pod or a specific container within the pod. Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The pod name container: Optional container name (if pod has multiple containers) tail_lines: Number of lines to retrieve from the end of the logs previous: Whether to get logs from a previous instance of the container Returns: Pod logs """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] logs = core_v1.read_namespaced_pod_log( name=name, namespace=namespace, container=container, tail_lines=tail_lines, previous=previous ) result = { "name": name, "namespace": namespace, "container": container, "logs": logs } return result