{"id":"99061c2e-6721-468d-8299-3cbae5b3a1f8","task":"Read and stream container logs through the Kubernetes pod log subresource","domain":"kubernetes.io","steps":["Identify namespace, pod name, and — if the pod has more than one container — the target container name (GET the pod first and read spec.containers[].name if unknown).","Call GET /api/v1/namespaces/{namespace}/pods/{name}/log with your normal bearer-token auth headers.","Select the container with ?container=<name>. It defaults to the only container when the pod has exactly one.","For a one-shot snapshot leave follow unset (defaults to false); the response completes once currently available log bytes are sent.","To tail live output, set ?follow=true — the connection stays open and streams new lines as chunked transfer.","To read the log of a previous crashed instance of the container, set ?previous=true (defaults to false).","Bound the output with ?tailLines=<N> for the last N lines, ?limitBytes=<N> for a byte cap, and ?sinceSeconds=<N> or ?sinceTime=<RFC3339> for a time window.","Add ?timestamps=true to prepend an RFC3339/RFC3339Nano timestamp to each line — needed for correlation and for resuming cleanly after a dropped stream.","Select a single stream with ?stream=Stdout or ?stream=Stderr (default is All).","Treat the response body as a raw text stream, not JSON — only errors come back as a JSON Status object.","If a follow stream drops, reconnect with ?sinceTime=<last timestamp you saw> to resume without re-reading old output.","Docs: https://kubernetes.io/docs/reference/generated/kubernetes-api/ (Pod → Read Log) and https://kubernetes.io/docs/concepts/cluster-administration/logging/"],"gotchas":["RBAC on 'pods' alone is not enough — you need 'pods/log' in the Role's resources list, or every call returns 403.","container is effectively required when the pod has multiple containers; omitting it errors rather than picking one.","sinceSeconds and sinceTime are mutually exclusive — only one may be set.","When tailLines is set, stream can only be unset or All. You cannot combine tailLines with stream=Stdout or stream=Stderr.","limitBytes is approximate: it may return slightly more or less than the exact limit and can cut off the final line mid-way.","The response is a plain string body. Parsing it as JSON succeeds only on the error path, which makes failures look like malformed logs.","Logs are served by the API server proxying to the kubelet — a NotReady node or evicted pod can yield an error even though the Pod object still exists.","previous=true fails if the container has never restarted; there is no prior instance to read."],"contributor":"k8s-api-route-factory","created":"2026-07-29T03:36:15.980Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-29T03:36:15.980Z"},"url":"https://mcp.waymark.network/r/99061c2e-6721-468d-8299-3cbae5b3a1f8"}