get_pod_events
Retrieve Kubernetes pod events to diagnose issues and monitor pod lifecycle changes in your cluster.
Instructions
Get events for a specific Kubernetes pod. This is equivalent to the kubectl command:
`kubectl get events -n NAMESPACE --field-selector involvedObject.name=POD_NAME,involvedObject.kind=Pod`
Parameters
----------
pod_name : str
Name of the pod to retrieve events for.
namespace : str, optional
Namespace of the pod (default is "default").
Returns
-------
list of EventSummary
List of events associated with the specified pod. Each EventSummary has the following fields:
last_seen : Optional[datetime.datetime]
Timestamp of the last occurrence of the event (if available).
type : str
Type of the event.
reason : str
Reason for the event.
object : str
The object this event applies to.
message : str
Message describing the event.
Raises
------
K8sConfigError
If unable to initialize the K8S API.
K8sApiError
If the API call to list events fails.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pod_name | Yes | ||
| namespace | No | default |
Implementation Reference
- src/k8stools/k8s_tools.py:441-448 (schema)Pydantic model defining the output structure for events returned by get_pod_events.class EventSummary(BaseModel): """This is the representation of a Kubernetes Event""" last_seen: Optional[datetime.timedelta] # Time since event occurred type: str reason: str object: str message: str
- src/k8stools/k8s_tools.py:450-500 (handler)Core handler function that fetches pod events from Kubernetes API using field selector and maps to EventSummary objects.def get_pod_events(pod_name: str, namespace: str = "default") -> list[EventSummary]: """ Get events for a specific Kubernetes pod. This is equivalent to the kubectl command: `kubectl get events -n NAMESPACE --field-selector involvedObject.name=POD_NAME,involvedObject.kind=Pod` Parameters ---------- pod_name : str Name of the pod to retrieve events for. namespace : str, optional Namespace of the pod (default is "default"). Returns ------- list of EventSummary List of events associated with the specified pod. Each EventSummary has the following fields: last_seen : Optional[datetime.datetime] Timestamp of the last occurrence of the event (if available). type : str Type of the event. reason : str Reason for the event. object : str The object this event applies to. message : str Message describing the event. Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list events fails. """ global K8S if K8S is None: K8S = _get_api_client() logging.info(f"get_pod_events(pod_name={pod_name}, namespace={namespace})") field_selector = f"involvedObject.name={pod_name}" events = K8S.list_namespaced_event(namespace, field_selector=field_selector) now = datetime.datetime.now(datetime.timezone.utc) return [ EventSummary( last_seen=(now - event.last_timestamp) if event.last_timestamp else None, type=event.type, reason=event.reason, object=getattr(event.involved_object, 'name', pod_name), message=event.message, ) for event in events.items ]
- src/k8stools/k8s_tools.py:1101-1111 (registration)Registration of get_pod_events in the TOOLS list for MCP integration.TOOLS = [ get_namespaces, get_node_summaries, get_pod_summaries, get_pod_container_statuses, get_pod_events, get_pod_spec, get_logs_for_pod_and_container, get_deployment_summaries, get_service_summaries ]