Retrieving Pod Logs by Label
Instead of specifying individual pod names, you can filter pods by their labels. For instance, if your pods are labeled withapp=notes-app, you can fetch their logs using:
Using labels to filter pods simplifies log retrieval and enhances troubleshooting by aggregating logs from multiple pods in one command.
Examining the Deployment’s Labels
Before querying logs, it’s important to verify the labels assigned to your deployment. For the Notes app deployment, you can inspect the labels with the following command:app: notes-app.
Retrieving Logs from Multiple Pods
Since the Notes app deployment is configured with two replicas, there are two pods running with the same label. To retrieve logs from both pods simultaneously, you need to specify the namespace and use the label selector with the-l flag:
app=notes-app label. A typical terminal session might look like this:
app=notes-app), the command returns logs from both pods seamlessly.
Using label selectors for logging is an efficient technique for monitoring real-time application behavior across multiple pods. This can significantly reduce the overhead of troubleshooting individual pod issues.