Skip to content

Kubernetes & OpenShift: Logs

Kubernetes & OpenShift commands for logs (tags: #logs #cloudwatch).

Index
4 items

Kubernetes3

Kubernetes: Follow logs of a pod

Safe

Stream a pod's logs from the last 200 lines. Add -c <container> for multi-container pods.

kubectl logs -f <pod> -n <namespace> --tail=200
What each part does
  1. kubectl logsprint a container's logs
  2. -ffollow: keep streaming
  3. <pod>the pod (add -c <container> if it has several)
  4. -n <namespace>namespace of the pod
  5. --tail=200start with the last 200 lines
Example
$ kubectl logs -f api-7c9d8b6f4-x2k9p -n shop --tail=200

Also known as: k8s logs · kubectl logs -f · pod logs

Kubernetes: Show logs of the previous crashed container

Safe

Logs from the container instance that just died: the one with the actual error.

kubectl logs <pod> -n <namespace> --previous
What each part does
  1. kubectl logs <pod>print container logs
  2. -n <namespace>namespace of the pod
  3. --previouslogs of the last terminated instance, i.e. the one that crashed, not the restarted one

My note First thing to run on CrashLoopBackOff.

Also known as: CrashLoopBackOff · previous logs · container restarted

Kubernetes: List recent events sorted by time

Safe

Scheduling failures, probe failures, image pulls, evictions: newest last.

kubectl get events -n <namespace> --sort-by=.lastTimestamp
What each part does
  1. kubectl get eventslist events: scheduling, pulls, probe failures, kills
  2. -n <namespace>in this namespace
  3. --sort-by=.lastTimestampoldest first, newest at the bottom

Also known as: k8s events · Back-off restarting failed container · Readiness probe failed

OpenShift1

OpenShift: Follow build logs

Safe

Stream the logs of the latest build of a BuildConfig.

oc logs -f bc/<build-config>
What each part does
  1. oc logs -ffollow logs
  2. bc/<build-config>the latest build of this BuildConfig

Also known as: build logs · s2i

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…