Skip to content

Instantly share code, notes, and snippets.

@topmangarbuja
Last active May 13, 2024 23:24
Show Gist options
  • Save topmangarbuja/86ee2477ec7d9ecaa22e78ad04de057f to your computer and use it in GitHub Desktop.
Save topmangarbuja/86ee2477ec7d9ecaa22e78ad04de057f to your computer and use it in GitHub Desktop.

View logs of multiple pods

- View logs of a single pod

kubectl logs <pod-name>

- View logs of muliple pods defined by a specific label

There could be multiple pods related to a single deployment. For example,there are 3 pods for API because you want to have 3 instances of API.

Use the folowing command to begin streaming the logs of the pods defined by label app=core-api

kubectl logs -f -l app=core-api
-f, --follow=false:
	Specify if the logs should be streamed.
-l, --selector='':
  Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching
	objects must satisfy all of the specified label constraints.

You can specify other options as well such as:

--all-containers=false:
	Get all containers' logs in the pod(s).
--since=0s:
	Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of
	since-time / since may be used

For more options, execute the following command kubectl logs -h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment