New to Kestra?
Use blueprints to kickstart your first workflows.
Automate Kubernetes pod log and event collection across a namespace with Kestra. Fetch logs from every pod in a time window for debugging and observability.
Collecting logs from a busy Kubernetes namespace usually means running kubectl logs pod by pod, then chasing down namespace events separately to understand what actually happened. This blueprint turns that manual scramble into a single, repeatable Kestra flow: it lists every pod in a target namespace, pulls each pod's logs for a chosen time window, and gathers the namespace events alongside them. The result is a consistent, auditable snapshot of cluster activity for debugging incidents, building observability routines, and capturing evidence before pods are recycled.
get_pods (io.kestra.plugin.kubernetes.kubectl.Get) connects to the cluster API server and lists all pods in the namespace from inputs.namespace, using fetchType: FETCH to return pod metadata as flow outputs.extract_pod_names (io.kestra.plugin.core.output.OutputValues) parses that metadata with a jq expression to build a clean array of pod names.fetch_logs_per_pod (io.kestra.plugin.core.flow.ForEach) iterates over the pod list with a concurrencyLimit of 5, running the fetch_logs shell task per pod. Each kubectl logs call uses --since={{ inputs.since }}, --all-containers=true, and --ignore-errors=true so multi-container pods are covered without failing the run.fetch_events (io.kestra.plugin.scripts.shell.Commands) runs kubectl get events for the namespace, sorted by .lastTimestamp, for the full activity picture.Shell tasks run in the bitnami/kubectl container via pluginDefaults, with the client certificate, client key, and CA cert injected as inputFiles so authentication is consistent across every task.
10m, 30m, 1h, 24h, and so on).kubectl is great for one-off commands but has no scheduler, no retries, and no history. With Kestra you can attach event triggers and schedules, get automatic retries on transient API failures, and keep full execution lineage of every log capture in one place. The declarative YAML makes the whole routine version-controlled and reviewable, something a loose shell script or a bare cron entry cannot offer.
io.kestra.plugin.kubernetes and io.kestra.plugin.scripts plugins (bundled in Kestra).bitnami/kubectl container image.Configure these secrets in your Kestra instance:
masterUrl: the Kubernetes API server URL.client.crt: client certificate for API authentication.client.key: client private key for API authentication.ca.crt: cluster certificate authority certificate.masterUrl, client.crt, client.key, and ca.crt secrets to your Kestra instance.system namespace.namespace and since inputs (defaults: kestra and 1h).Schedule trigger to capture logs on a fixed cadence.Slack or email notification when error patterns appear in the logs.