Kubectl logs command to view pod logs

Tasrie IT Services

Tasrie IT Services

·3 min read
Kubectl logs command to view pod logs

In this article, we'll take a deep dive into kubectl logs, a command-line tool that allows you to access and manage your apps on Kubernetes. We'll explore what this command is, why it's essential, and how to use it. We'll also look at some common errors and best practices for using this command.

What is kubectl logs?

This is a command-line tool that allows you to access and manage Kubernetes logs. With this command, you can view the logs of a Kubernetes Pod, filter and follow logs in real-time, and export logs to a file.

Kubernetes logs are critical for monitoring the health and performance of your applications and services. This command can help you troubleshoot issues, identify errors, and optimize your applications and services. This allows you to access and manage Kubernetes logs with ease, providing critical insights into your applications and services' health and performance.

How to use kubectl logs?

First, you need to have a Kubernetes cluster set up and running. Once you have a Kubernetes cluster, you can use to access and manage Kubernetes logs. Here's how:

Viewing Kubernetes Pod logs

To view the logs of a Kubernetes Pod, run the following command:

bash
kubectl logs <pod-name>

Filtering Kubernetes Pod logs

You can filter Kubernetes Pod logs using the following options:

  • –since: Displays logs since a specific timestamp. For example:
bash
kubectl logs <pod-name> --since=1h
  • –tail: Displays the last N lines of logs. For example:
bash
kubectl logs <pod-name> --tail=100
  • –container: Displays the logs of a specific container in a Pod. For example:
bash
kubectl logs <pod-name> --container=<container-name>

Tail Kubernetes Pod logs

You can follow Kubernetes Pod logs in real-time the following option:

  • -f: Follows the logs in real-time. For example:
bash
kubectl logs <pod-name> -f

kubectl view multiple pod logs

If a Kubernetes Pod has multiple containers. you can use this awesome utility stern to view/tail multiple pod logs. To use this utility you need to install it first.

How to Install stern on Mac

If you use Homebrew, you can install like this:

bash
brew install stern

other installation options are available here.

Stern Usage

bash
stern -l app=<deployment-label> -n <namespace>

Stern supports many other ways to tails multiple pod logs. you can check out here

For more such content, make sure to check out our latest tech blog

Follow our LinkedIn Page

illustration
Need Expert Help ?

At Tasrie IT, we assist businesses in their growth and addressing intricate issues by utilizing advanced cloud technologies and contemporary platform engineering techniques.

Related Posts